linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	akpm@linux-foundation.org, willy@infradead.org, arnd@kernel.org,
	Willem de Bruijn <willemb@google.com>,
	Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 5/6] compat: add set_maybe_compat_user_sigmask helper
Date: Mon, 11 Jan 2021 19:30:16 -0500	[thread overview]
Message-ID: <20210112003017.4010304-6-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20210112003017.4010304-1-willemdebruijn.kernel@gmail.com>

From: Willem de Bruijn <willemb@google.com>

Deduplicate the open coded branch on sigmask compat handling.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
---
 fs/eventpoll.c         |  5 +----
 fs/io_uring.c          |  9 +--------
 fs/select.c            | 10 ++--------
 include/linux/compat.h | 10 ++++++++++
 4 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index c9dcffba2da1..c011327c8402 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -2247,10 +2247,7 @@ static int do_epoll_pwait(int epfd, struct epoll_event __user *events,
 	 * If the caller wants a certain signal mask to be set during the wait,
 	 * we apply it here.
 	 */
-	if (!in_compat_syscall())
-		error = set_user_sigmask(sigmask, sigsetsize);
-	else
-		error = set_compat_user_sigmask(sigmask, sigsetsize);
+	error = set_maybe_compat_user_sigmask(sigmask, sigsetsize);
 	if (error)
 		return error;
 
diff --git a/fs/io_uring.c b/fs/io_uring.c
index fdc923e53873..abc88bc738ce 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7190,14 +7190,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
 	} while (1);
 
 	if (sig) {
-#ifdef CONFIG_COMPAT
-		if (in_compat_syscall())
-			ret = set_compat_user_sigmask((const compat_sigset_t __user *)sig,
-						      sigsz);
-		else
-#endif
-			ret = set_user_sigmask(sig, sigsz);
-
+		ret = set_maybe_compat_user_sigmask(sig, sigsz);
 		if (ret)
 			return ret;
 	}
diff --git a/fs/select.c b/fs/select.c
index 27567795a892..c013662bbf51 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -773,10 +773,7 @@ static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
 			return -EINVAL;
 	}
 
-	if (!in_compat_syscall())
-		ret = set_user_sigmask(sigmask, sigsetsize);
-	else
-		ret = set_compat_user_sigmask(sigmask, sigsetsize);
+	ret = set_maybe_compat_user_sigmask(sigmask, sigsetsize);
 	if (ret)
 		return ret;
 
@@ -1146,10 +1143,7 @@ static int do_ppoll(struct pollfd __user *ufds, unsigned int nfds,
 			return -EINVAL;
 	}
 
-	if (!in_compat_syscall())
-		ret = set_user_sigmask(sigmask, sigsetsize);
-	else
-		ret = set_compat_user_sigmask(sigmask, sigsetsize);
+	ret = set_maybe_compat_user_sigmask(sigmask, sigsetsize);
 	if (ret)
 		return ret;
 
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 6e65be753603..4a9b740496b4 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -18,6 +18,7 @@
 #include <linux/aio_abi.h>	/* for aio_context_t */
 #include <linux/uaccess.h>
 #include <linux/unistd.h>
+#include <linux/sched/signal.h>
 
 #include <asm/compat.h>
 
@@ -942,6 +943,15 @@ static inline bool in_compat_syscall(void) { return false; }
 
 #endif /* CONFIG_COMPAT */
 
+static inline int set_maybe_compat_user_sigmask(const void __user *umask,
+						size_t sigsetsize)
+{
+	if (!in_compat_syscall())
+		return set_user_sigmask(umask, sigsetsize);
+	else
+		return set_compat_user_sigmask(umask, sigsetsize);
+}
+
 /*
  * Some legacy ABIs like the i386 one use less than natural alignment for 64-bit
  * types, and will need special compat treatment for that.  Most architectures
-- 
2.30.0.284.gd98b1dd5eaa7-goog


  parent reply	other threads:[~2021-01-12  0:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  0:30 [PATCH 0/6] fs: deduplicate compat logic Willem de Bruijn
2021-01-12  0:30 ` [PATCH 1/6] selftests/filesystems: add initial select and poll selftest Willem de Bruijn
2021-01-12  0:30 ` [PATCH 2/6] select: deduplicate compat logic Willem de Bruijn
2021-01-12  0:30 ` [PATCH 3/6] ppoll: " Willem de Bruijn
2021-01-12  0:30 ` [PATCH 4/6] epoll: " Willem de Bruijn
2021-01-12  0:30 ` Willem de Bruijn [this message]
2021-01-12  7:11   ` [PATCH 5/6] compat: add set_maybe_compat_user_sigmask helper kernel test robot
2021-01-12  0:30 ` [PATCH 6/6] io_pgetevents: deduplicate compat logic Willem de Bruijn
2021-01-12  0:58 ` [PATCH 0/6] fs: " Al Viro
2021-01-12  1:16   ` Willem de Bruijn

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=20210112003017.4010304-6-willemdebruijn.kernel@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemb@google.com \
    --cc=willy@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).