LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Linux-Arch <linux-arch@vger.kernel.org>
Cc: "Anton Ivanov" <anton.ivanov@kot-begemot.co.uk>,
	"Richard Weinberger" <richard.weinberger@gmail.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Jeff Dike" <jdike@addtoit.com>,
	linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
	user-mode-linux-devel@lists.sourceforge.net,
	"Martin Pärtel" <martin.partel@gmail.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [REVIEW][PATCH 1/5] signal/signalfd: Remove __put_user from signalfd_copyinfo
Date: Sat, 28 Apr 2018 09:06:58 -0500	[thread overview]
Message-ID: <20180428140702.3925-1-ebiederm@xmission.com> (raw)
In-Reply-To: <87zi1nctut.fsf_-_@xmission.com>

Put a signalfd_siginfo structure on the stack fully initializae
it and then copy it to userspace.

The code is a little less wordy, and this avoids a long series
of the somewhat costly __put_user calls.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 fs/signalfd.c | 56 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/fs/signalfd.c b/fs/signalfd.c
index ff302bf50be4..31e960209a08 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -81,41 +81,41 @@ static __poll_t signalfd_poll(struct file *file, poll_table *wait)
 static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 			     siginfo_t const *kinfo)
 {
-	long err;
+	struct signalfd_siginfo new;
 
 	BUILD_BUG_ON(sizeof(struct signalfd_siginfo) != 128);
 
 	/*
 	 * Unused members should be zero ...
 	 */
-	err = __clear_user(uinfo, sizeof(*uinfo));
+	memset(&new, 0, sizeof(new));
 
 	/*
 	 * If you change siginfo_t structure, please be sure
 	 * this code is fixed accordingly.
 	 */
-	err |= __put_user(kinfo->si_signo, &uinfo->ssi_signo);
-	err |= __put_user(kinfo->si_errno, &uinfo->ssi_errno);
-	err |= __put_user(kinfo->si_code, &uinfo->ssi_code);
+	new.ssi_signo = kinfo->si_signo;
+	new.ssi_errno = kinfo->si_errno;
+	new.ssi_code  = kinfo->si_code;
 	switch (siginfo_layout(kinfo->si_signo, kinfo->si_code)) {
 	case SIL_KILL:
-		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
-		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
+		new.ssi_pid = kinfo->si_pid;
+		new.ssi_uid = kinfo->si_uid;
 		break;
 	case SIL_TIMER:
-		 err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid);
-		 err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun);
-		 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
-		 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
+		new.ssi_tid = kinfo->si_tid;
+		new.ssi_overrun = kinfo->si_overrun;
+		new.ssi_ptr = (long) kinfo->si_ptr;
+		new.ssi_int = kinfo->si_int;
 		break;
 	case SIL_POLL:
-		err |= __put_user(kinfo->si_band, &uinfo->ssi_band);
-		err |= __put_user(kinfo->si_fd, &uinfo->ssi_fd);
+		new.ssi_band = kinfo->si_band;
+		new.ssi_fd   = kinfo->si_fd;
 		break;
 	case SIL_FAULT:
-		err |= __put_user((long) kinfo->si_addr, &uinfo->ssi_addr);
+		new.ssi_addr = (long) kinfo->si_addr;
 #ifdef __ARCH_SI_TRAPNO
-		err |= __put_user(kinfo->si_trapno, &uinfo->ssi_trapno);
+		new.ssi_trapno = kinfo->si_trapno;
 #endif
 		/*
 		 * Other callers might not initialize the si_lsb field,
@@ -124,29 +124,31 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 		if (kinfo->si_signo == SIGBUS &&
 		    ((kinfo->si_code == BUS_MCEERR_AR) ||
 		     (kinfo->si_code == BUS_MCEERR_AO)))
-			err |= __put_user((short) kinfo->si_addr_lsb,
-					  &uinfo->ssi_addr_lsb);
+			new.ssi_addr_lsb = (short) kinfo->si_addr_lsb;
 		break;
 	case SIL_CHLD:
-		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
-		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
-		err |= __put_user(kinfo->si_status, &uinfo->ssi_status);
-		err |= __put_user(kinfo->si_utime, &uinfo->ssi_utime);
-		err |= __put_user(kinfo->si_stime, &uinfo->ssi_stime);
+		new.ssi_pid    = kinfo->si_pid;
+		new.ssi_uid    = kinfo->si_uid;
+		new.ssi_status = kinfo->si_status;
+		new.ssi_utime  = kinfo->si_utime;
+		new.ssi_stime  = kinfo->si_stime;
 		break;
 	case SIL_RT:
 	default:
 		/*
 		 * This case catches also the signals queued by sigqueue().
 		 */
-		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
-		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
-		err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
-		err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
+		new.ssi_pid = kinfo->si_pid;
+		new.ssi_uid = kinfo->si_uid;
+		new.ssi_ptr = (long) kinfo->si_ptr;
+		new.ssi_int = kinfo->si_int;
 		break;
 	}
 
-	return err ? -EFAULT: sizeof(*uinfo);
+	if (copy_to_user(uinfo, &new, sizeof(struct signalfd_siginfo)))
+		return -EFAULT;
+
+	return sizeof(*uinfo);
 }
 
 static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, siginfo_t *info,
-- 
2.14.1

  reply	other threads:[~2018-04-28 14:07 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20  1:01 [REVIEW][PATCH 00/17] siginfo bugfixes and cleanups Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 01/17] signal/alpha: Document a conflict with SI_USER for SIGFPE Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 02/17] sparc: fix compat siginfo ABI regression Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 03/17] signal/sh: Use force_sig_fault in hw_breakpoint_handler Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 04/17] signal/nds32: Use force_sig in unhandled_interruption and unhandled_exceptions Eric W. Biederman
2018-04-25 12:14   ` Vincent Chen
2018-04-20  1:03 ` [REVIEW][PATCH 05/17] signal/nds32: Use force_sig(SIGILL) in do_revisn Eric W. Biederman
2018-04-25 12:10   ` Vincent Chen
2018-04-25 16:13     ` [PATCH] signal/nds32: More information in do_revinsn Eric W. Biederman
2018-04-26  3:02       ` Vincent Chen
2018-04-20  1:03 ` [REVIEW][PATCH 06/17] signal: Ensure every siginfo we send has all bits initialized Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 07/17] signal: Reduce copy_siginfo_to_user to just copy_to_user Eric W. Biederman
2018-04-20  1:03 ` [REVIEW][PATCH 08/17] signal: Stop special casing TRAP_FIXME and FPE_FIXME in siginfo_layout Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 09/17] signal: Remove SEGV_BNDERR ifdefs Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 10/17] signal: Remove ifdefs for BUS_MCEERR_AR and BUS_MCEERR_AO Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 11/17] signal/alpha: Replace FPE_FIXME with FPE_FLTUNK Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 12/17] signal/ia64: " Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 13/17] signal/powerpc: " Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 14/17] signal/unicore32: Use FPE_FLTUNK instead of 0 in ucf64_raise_sigfpe Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 15/17] signal: Add TRAP_UNK si_code for undiagnosted trap exceptions Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 16/17] signal/alpha: Replace TRAP_FIXME with TRAP_UNK Eric W. Biederman
2018-04-20  1:04 ` [REVIEW][PATCH 17/17] signal/powerpc: " Eric W. Biederman
2018-04-20 14:35 ` [REVIEW][PATCH 00/22] Simplifying siginfo users Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 01/22] signal/alpha: Use send_sig_fault where appropriate Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 02/22] signal/alpha: Use force_sig_fault " Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 03/22] signal/c6x: " Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 04/22] signal/hexagon: Use force_sig_fault as appropriate Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 05/22] signal/m68k: Use force_sig_fault where appropriate Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 06/22] signal/microblaze: Remove the commented out force_sig_info in do_page_fault Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 07/22] signal/microblaze: Use force_sig_fault where appropriate Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 08/22] signal/mips: " Eric W. Biederman
2018-05-09 15:14     ` Matt Redfearn
2018-05-10  2:39       ` Eric W. Biederman
2018-05-10  7:59         ` Matt Redfearn
2018-05-11  2:31           ` Eric W. Biederman
2018-04-20 14:37   ` [REVIEW][PATCH 09/22] signal/nds32: " Eric W. Biederman
2018-04-25 11:29     ` Vincent Chen
2018-04-25 15:57       ` Eric W. Biederman
2018-04-26  1:24         ` Greentime Hu
2018-04-20 14:37   ` [REVIEW][PATCH 10/22] signal/nios2: " Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 11/22] signal/openrisc: " Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 12/22] signal/parisc: Use force_sig_mceerr " Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 13/22] signal/parisc: Use force_sig_fault " Eric W. Biederman
2018-04-21 17:24     ` Helge Deller
2018-04-20 14:38   ` [REVIEW][PATCH 14/22] signal/riscv: " Eric W. Biederman
2018-04-21  7:25     ` Christoph Hellwig
2018-04-24 15:31       ` [REVIEW][PATCH 23/22] signal/riscv: Replace do_trap_siginfo with force_sig_fault Eric W. Biederman
2018-04-23 19:11     ` [REVIEW][PATCH 14/22] signal/riscv: Use force_sig_fault where appropriate Palmer Dabbelt
2018-04-24 15:28       ` Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 15/22] signal/s390: " Eric W. Biederman
2018-04-23  5:44     ` Martin Schwidefsky
2018-04-20 14:38   ` [REVIEW][PATCH 16/22] signal/sh: " Eric W. Biederman
2018-04-20 14:55     ` Rich Felker
2018-05-28  9:19       ` Geert Uytterhoeven
2018-05-29 15:00         ` [PATCH] signal/sh: Stop gcc warning about an impossible case in do_divide_error Eric W. Biederman
2018-05-30  7:54           ` Sergei Shtylyov
2018-04-20 14:38   ` [REVIEW][PATCH 17/22] signal/sparc: Use send_sig_fault where appropriate Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 18/22] signal/sparc: Use force_sig_fault " Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 19/22] signal/um: Use force_sig_fault in relay_signal Eric W. Biederman
2018-04-20 16:06     ` [uml-devel] " Anton Ivanov
2018-04-24  8:32       ` Richard Weinberger
2018-04-24  8:44         ` Anton Ivanov
2018-04-24 15:59           ` Eric W. Biederman
     [not found]             ` <CAMD8JhwgcWCp6c=O4-spNW1VdY5M-eAjr7M5PieeAfeTSe_4yw@mail.gmail.com>
2018-04-24 22:03               ` Martin Pärtel
2018-04-24 22:24                 ` Eric W. Biederman
2018-04-25 23:05                   ` Martin Pärtel
2018-04-28 14:02                     ` [REVIEW][PATCH 0/5] Improving siginfo_layout and fixing uml's relay_signal Eric W. Biederman
2018-04-28 14:06                       ` Eric W. Biederman [this message]
2018-04-28 14:06                       ` [REVIEW][PATCH 2/5] signal/signalfd: Add support for SIGSYS Eric W. Biederman
2018-04-28 14:07                       ` [REVIEW][PATCH 3/5] signal: Remove unncessary #ifdef SEGV_PKUERR in 32bit compat code Eric W. Biederman
2018-04-28 14:07                       ` [REVIEW][PATCH 4/5] signal: Extend siginfo_layout with SIL_FAULT_{MCEERR|BNDERR|PKUERR} Eric W. Biederman
2018-04-28 14:07                       ` [REVIEW][PATCH 5/5] signal/um: More carefully relay signals in relay_signal Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 20/22] signal/um: Use force_sig_fault where appropriate Eric W. Biederman
2018-04-20 14:38   ` [REVIEW][PATCH 21/22] signal/xtensa: Consistenly use SIGBUS in do_unaligned_user Eric W. Biederman
2018-04-20 16:06     ` Max Filippov
2018-04-20 14:38   ` [REVIEW][PATCH 22/22] signal/xtensa: Use force_sig_fault where appropriate Eric W. Biederman
2018-04-20 16:27     ` Max Filippov

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=20180428140702.3925-1-ebiederm@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=anton.ivanov@kot-begemot.co.uk \
    --cc=jdike@addtoit.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=martin.partel@gmail.com \
    --cc=richard.weinberger@gmail.com \
    --cc=richard@nod.at \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    --subject='Re: [REVIEW][PATCH 1/5] signal/signalfd: Remove __put_user from signalfd_copyinfo' \
    /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).