aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-08 15:02:09 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-08 15:02:09 +0100
commit3adb015fe0741b6b3143be4e96599a3b013b1589 (patch)
tree6a75eeb1b0820c0980b5b624ea3536918d1e4091
parent929b9552f90bc399454f49ed993c796bf1f17863 (diff)
downloadpseudo-3adb015fe0741b6b3143be4e96599a3b013b1589.tar.gz
pseudo-3adb015fe0741b6b3143be4e96599a3b013b1589.tar.bz2
pseudo-3adb015fe0741b6b3143be4e96599a3b013b1589.zip
pseudo.c: Improve handling of entries with nlink == 0 in fd ops
Some operations may call unlink() on an open fd, then call fchown/fchmod/fstat on that fd. This would currently readd its entry to the database, which is necessary to preserve its permissions information however since that file will be lost when it is closed, we don't want the DB entry to persist. Marking it as may_unlink means the code will know its likely been deleted and ignore the entry later, giving improved behaviour that simple path mismatch warnings. We can use an nlink of zero to detect this. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--pseudo.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/pseudo.c b/pseudo.c
index 331a20c..ff8e1b9 100644
--- a/pseudo.c
+++ b/pseudo.c
@@ -1023,6 +1023,21 @@ pseudo_op(pseudo_msg_t *msg, const char *program, const char *tag, char **respon
break;
}
+ switch (msg->op) {
+ case OP_FCHOWN: /* FALLTHROUGH */
+ case OP_FCHMOD: /* FALLTHROUGH */
+ case OP_FSTAT:
+ if (!found_path && !found_ino && (msg->nlink == 0)) {
+ /* If nlink is 0 for an fchown/fchmod/fstat, we probably have an fd which is
+ * unlinked and we don't want to do inode/path matching against it. Marking it
+ * as may unlink gives the right hints in the database to ensure we
+ * handle correctly whilst maintaining the permissions whilst the
+ * file exists for the fd. */
+ pdb_may_unlink_file(msg, msg->client);
+ }
+ break;
+ }
+
op_exit:
/* in the case of an exact match, we just used the pointer
* rather than allocating space.