From 9bdb06339db63a33dcf7570ed785236ecf27c287 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Jun 2020 14:32:00 +0200 Subject: [PATCH] 4.19-stable patches added patches: aio-fix-async-fsync-creds.patch --- queue-4.19/aio-fix-async-fsync-creds.patch | 73 ++++++++++++++++++++++ queue-4.19/series | 1 + 2 files changed, 74 insertions(+) create mode 100644 queue-4.19/aio-fix-async-fsync-creds.patch diff --git a/queue-4.19/aio-fix-async-fsync-creds.patch b/queue-4.19/aio-fix-async-fsync-creds.patch new file mode 100644 index 00000000000..f063bbf9f9d --- /dev/null +++ b/queue-4.19/aio-fix-async-fsync-creds.patch @@ -0,0 +1,73 @@ +From 530f32fc370fd1431ea9802dbc53ab5601dfccdb Mon Sep 17 00:00:00 2001 +From: Miklos Szeredi +Date: Thu, 14 May 2020 16:44:24 +0200 +Subject: aio: fix async fsync creds + +From: Miklos Szeredi + +commit 530f32fc370fd1431ea9802dbc53ab5601dfccdb upstream. + +Avi Kivity reports that on fuse filesystems running in a user namespace +asyncronous fsync fails with EOVERFLOW. + +The reason is that f_ops->fsync() is called with the creds of the kthread +performing aio work instead of the creds of the process originally +submitting IOCB_CMD_FSYNC. + +Fuse sends the creds of the caller in the request header and it needs to +translate the uid and gid into the server's user namespace. Since the +kthread is running in init_user_ns, the translation will fail and the +operation returns an error. + +It can be argued that fsync doesn't actually need any creds, but just +zeroing out those fields in the header (as with requests that currently +don't take creds) is a backward compatibility risk. + +Instead of working around this issue in fuse, solve the core of the problem +by calling the filesystem with the proper creds. + +Reported-by: Avi Kivity +Tested-by: Giuseppe Scrivano +Fixes: c9582eb0ff7d ("fuse: Fail all requests with invalid uids or gids") +Cc: stable@vger.kernel.org # 4.18+ +Signed-off-by: Miklos Szeredi +Reviewed-by: Christoph Hellwig +Signed-off-by: Greg Kroah-Hartman + +--- + fs/aio.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +--- a/fs/aio.c ++++ b/fs/aio.c +@@ -169,6 +169,7 @@ struct fsync_iocb { + struct file *file; + struct work_struct work; + bool datasync; ++ struct cred *creds; + }; + + struct poll_iocb { +@@ -1579,8 +1580,11 @@ static ssize_t aio_write(struct kiocb *r + static void aio_fsync_work(struct work_struct *work) + { + struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); ++ const struct cred *old_cred = override_creds(iocb->fsync.creds); + + iocb->ki_res.res = vfs_fsync(iocb->fsync.file, iocb->fsync.datasync); ++ revert_creds(old_cred); ++ put_cred(iocb->fsync.creds); + iocb_put(iocb); + } + +@@ -1594,6 +1598,10 @@ static int aio_fsync(struct fsync_iocb * + if (unlikely(!req->file->f_op->fsync)) + return -EINVAL; + ++ req->creds = prepare_creds(); ++ if (!req->creds) ++ return -ENOMEM; ++ + req->datasync = datasync; + INIT_WORK(&req->work, aio_fsync_work); + schedule_work(&req->work); diff --git a/queue-4.19/series b/queue-4.19/series index eb04d3c102c..3e619f9641e 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -23,4 +23,5 @@ rdma-uverbs-make-the-event_queue-fds-return-pollerr-.patch x86-cpu-amd-make-erratum-1054-a-legacy-erratum.patch perf-probe-accept-the-instance-number-of-kretprobe-e.patch mm-add-kvfree_sensitive-for-freeing-sensitive-data-o.patch +aio-fix-async-fsync-creds.patch btrfs-tree-checker-check-level-for-leaves-and-nodes.patch -- 2.47.3