Skip to contentSkip to conversation

fuse: enforce file modes for io_uring commands

PATCH New Sieun Yang 1 participant 1 message Nov 18

Subsystems (2)
lore
Share & tools
lore

Sieun Yang

author
#0 lore raw

PATCH 1/1 fuse: enforce file modes for io_uring commands

Ordinary read() and write() enforce FMODE_READ and FMODE_WRITE before reaching FUSE. IORING_OP_URING_CMD does not, and FUSE's command handler does not check either mode. REGISTER can therefore deliver requests through an O_WRONLY connection. COMMIT_AND_FETCH also enters its reply-and-fetch path through an O_RDONLY connection.

This can expose data to a process given only a write-only FUSE connection. On 7.4.0-rc3-g20eef29b7c84 with fuse.enable_uring=1, uid 1000 received a FUSE_WRITE request containing 36 bytes written by uid 2000 after being passed only an O_WRONLY connection fd. Ordinary read() on that fd returned EBADF, and new O_RDONLY and O_RDWR opens of /dev/fuse were denied. The mount used default_permissions and a file owned by uid 2000 with mode 0200.

Require FMODE_READ for REGISTER. COMMIT_AND_FETCH both submits a reply and fetches the next request, so require FMODE_READ and FMODE_WRITE. The same test returned EBADF for REGISTER with the change applied.

Fixes 24fe962c86f5 ("fuse: {io-uring} Handle SQEs - register commands")
Fixes c090c8abae4b ("fuse: Add io-uring sqe commit and fetch support")
---
 fs/fuse/dev_uring.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/fuse/dev_uring.c +5 -0
index 460776cd6..481368ac9 100644
@@ -1698,6 +1698,8 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
 
 	switch (cmd_op) {
 	case FUSE_IO_URING_CMD_REGISTER:
+		if (!(cmd->file->f_mode & FMODE_READ))
+			return -EBADF;
 		err = fuse_uring_register(cmd, issue_flags, fch);
 		if (err) {
 			pr_info_once("FUSE_IO_URING_CMD_REGISTER failed err=%d\n",
@@ -1708,6 +1710,9 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
 		}
 		break;
 	case FUSE_IO_URING_CMD_COMMIT_AND_FETCH:
+		if ((cmd->file->f_mode & (FMODE_READ | FMODE_WRITE)) !=
+		    (FMODE_READ | FMODE_WRITE))
+			return -EBADF;
 		err = fuse_uring_commit_fetch(cmd, issue_flags, fch);
 		if (err) {
 			pr_info_once("FUSE_IO_URING_COMMIT_AND_FETCH failed err=%d\n",

base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca

Signature · 1 line
2.39.5