linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yangerkun <yangerkun@huawei.com>
To: <miklos@szeredi.hu>, <amir73il@gmail.com>,
	<jiufei.xue@linux.alibaba.com>
Cc: <linux-unionfs@vger.kernel.org>, <yangerkun@huawei.com>,
	<yukuai3@huawei.com>
Subject: [PATCH 1/2] ovl: factor out ovl_get_aio_req
Date: Thu, 30 Sep 2021 11:22:27 +0800	[thread overview]
Message-ID: <20210930032228.3199690-2-yangerkun@huawei.com> (raw)
In-Reply-To: <20210930032228.3199690-1-yangerkun@huawei.com>

Factor out a common function to remove duplicate code in
ovl_read_iter/ovl_write_iter.

Signed-off-by: yangerkun <yangerkun@huawei.com>
---
 fs/overlayfs/file.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index d081faa55e83..4ac3cd698c7d 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -282,6 +282,23 @@ static void ovl_aio_rw_complete(struct kiocb *iocb, long res, long res2)
 	orig_iocb->ki_complete(orig_iocb, res, res2);
 }
 
+static struct ovl_aio_req *ovl_get_aio_req(struct kiocb *iocb, struct fd *real, int ifl)
+{
+	struct ovl_aio_req *req;
+
+	req = kmem_cache_zalloc(ovl_aio_request_cachep, GFP_KERNEL);
+	if (!req)
+		return NULL;
+
+	req->fd = *real;
+	real->flags = 0;
+	req->orig_iocb = iocb;
+	kiocb_clone(&req->iocb, iocb, real->file);
+	req->iocb.ki_flags = ifl;
+	req->iocb.ki_complete = ovl_aio_rw_complete;
+	return req;
+}
+
 static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 {
 	struct file *file = iocb->ki_filp;
@@ -304,15 +321,10 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 		struct ovl_aio_req *aio_req;
 
 		ret = -ENOMEM;
-		aio_req = kmem_cache_zalloc(ovl_aio_request_cachep, GFP_KERNEL);
+		aio_req = ovl_get_aio_req(iocb, &real, iocb->ki_flags);
 		if (!aio_req)
 			goto out;
 
-		aio_req->fd = real;
-		real.flags = 0;
-		aio_req->orig_iocb = iocb;
-		kiocb_clone(&aio_req->iocb, iocb, real.file);
-		aio_req->iocb.ki_complete = ovl_aio_rw_complete;
 		ret = vfs_iocb_iter_read(real.file, &aio_req->iocb, iter);
 		if (ret != -EIOCBQUEUED)
 			ovl_aio_cleanup_handler(aio_req);
@@ -364,7 +376,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 		struct ovl_aio_req *aio_req;
 
 		ret = -ENOMEM;
-		aio_req = kmem_cache_zalloc(ovl_aio_request_cachep, GFP_KERNEL);
+		aio_req = ovl_get_aio_req(iocb, &real, ifl);
 		if (!aio_req)
 			goto out;
 
@@ -372,12 +384,6 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 		/* Pacify lockdep, same trick as done in aio_write() */
 		__sb_writers_release(file_inode(real.file)->i_sb,
 				     SB_FREEZE_WRITE);
-		aio_req->fd = real;
-		real.flags = 0;
-		aio_req->orig_iocb = iocb;
-		kiocb_clone(&aio_req->iocb, iocb, real.file);
-		aio_req->iocb.ki_flags = ifl;
-		aio_req->iocb.ki_complete = ovl_aio_rw_complete;
 		ret = vfs_iocb_iter_write(real.file, &aio_req->iocb, iter);
 		if (ret != -EIOCBQUEUED)
 			ovl_aio_cleanup_handler(aio_req);
-- 
2.31.1


  reply	other threads:[~2021-09-30  3:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30  3:22 [PATCH 0/2] ovl: bugfix for ovl_aio_req yangerkun
2021-09-30  3:22 ` yangerkun [this message]
2021-09-30  3:22 ` [PATCH 2/2] ovl: fix UAF " yangerkun
2021-10-08  1:25   ` yangerkun
2021-10-08 15:13   ` Miklos Szeredi
2021-10-18 14:26     ` yangerkun
2021-10-28 12:41       ` yangerkun
2021-10-29  8:35         ` Miklos Szeredi
2021-10-29 11:40         ` Miklos Szeredi
2021-11-01  4:02           ` yangerkun
2021-11-01  9:15             ` Miklos Szeredi
2021-11-01 10:52               ` yangerkun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930032228.3199690-2-yangerkun@huawei.com \
    --to=yangerkun@huawei.com \
    --cc=amir73il@gmail.com \
    --cc=jiufei.xue@linux.alibaba.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=yukuai3@huawei.com \
    --subject='Re: [PATCH 1/2] ovl: factor out ovl_get_aio_req' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).