mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Benjamin LaHaise <bcrl@kvack.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] aio: rewrite aio_thread_op_foo_at to avoid 64-bit get_user
Date: Tue, 15 Mar 2016 22:38:51 +0100	[thread overview]
Message-ID: <1458077950-500866-1-git-send-email-arnd@arndb.de> (raw)

Most architectures cannot access 64-bit integers using get_user
or __get_user, so we get a build error in the new aio_thread_op_foo_at
function:

fs/built-in.o: In function `aio_thread_op_foo_at':
aio.c:(.text+0x252de): undefined reference to `__get_user_bad'
aio.c:(.text+0x252e4): undefined reference to `__get_user_bad'

This replaces the function with a different implementation using
copy_from_user() on the iocb, to avoid the problem. As there are
already three calls to get_user() in the function, this likely
ends up being more efficient in particular on architectures that
have strong memory protection between kernel and user space
and now only need to switch access modes once.

I've also tried to make the function more readable overall,
with local variable names matching the callback function
arguments in both type and name, rather than matching what
we get from user space.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: d2f7a973e11e ("aio: don't use __get_user() for 64 bit values")
---
 fs/aio.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 72a7e8a2f67e..1748fb97d991 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1777,25 +1777,23 @@ static long aio_do_unlinkat(int fd, const char *filename, int flags, int mode)
 
 static long aio_thread_op_foo_at(struct aio_kiocb *req)
 {
-	u64 buf, offset;
-	long ret;
-	u32 fd;
+	struct iocb iocb;
+	int fd;
+	const char __user *filename;
+	int flags, mode;
+	do_foo_at_t do_foo_at;
 
-	if (unlikely(get_user(fd, &req->ki_user_iocb->aio_fildes)))
-		ret = -EFAULT;
-	else if (unlikely(get_user(buf, &req->ki_user_iocb->aio_buf)))
-		ret = -EFAULT;
-	else if (unlikely(get_user(offset, &req->ki_user_iocb->aio_offset)))
-		ret = -EFAULT;
-	else {
-		do_foo_at_t do_foo_at = (void *)req->ki_data;
+	if (copy_from_user(&iocb, req->ki_user_iocb, sizeof(struct iocb)))
+		return -EFAULT;
 
-		ret = do_foo_at((s32)fd,
-				(const char __user *)(long)buf,
-				(int)offset,
-				(unsigned short)(offset >> 32));
-	}
-	return ret;
+	fd = (s32)iocb.aio_fildes;
+	filename = (const char __user *)(uintptr_t)iocb.aio_buf;
+	flags = (int)lower_32_bits(iocb.aio_offset);
+	mode = (unsigned short)upper_32_bits(iocb.aio_offset);
+
+	do_foo_at = (void *)req->ki_data;
+
+	return do_foo_at(fd, filename, flags, mode);
 }
 
 static void openat_destruct(struct aio_kiocb *req)
-- 
2.7.0

                 reply	other threads:[~2016-03-15 21:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1458077950-500866-1-git-send-email-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=bcrl@kvack.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®