From: Oleg Nesterov <oleg@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Howells <dhowells@redhat.com>,
Eugene Teo <eugene@redhat.com>, James Morris <jmorris@namei.org>,
Roland McGrath <roland@redhat.com>,
solar@openwall.com, linux-kernel@vger.kernel.org
Subject: [PATCH] send_sigio_to_task: sanitize the usage of fown->signum
Date: Wed, 17 Jun 2009 00:27:10 +0200 [thread overview]
Message-ID: <20090616222710.GA7620@redhat.com> (raw)
In-Reply-To: <20090616215103.GA4853@redhat.com>
send_sigio_to_task() reads fown->signum several times, we can race with
F_SETSIG which changes ->signum lockless. In theory, this can fool security
checks or we can call group_send_sig_info() with the wrong ->si_signo which
does not match "int sig".
Change the code to cache ->signum.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
--- a/fs/fcntl.c~signum 2009-06-16 21:41:18.000000000 +0200
+++ b/fs/fcntl.c 2009-06-17 00:11:38.000000000 +0200
@@ -426,14 +426,20 @@ static inline int sigio_perm(struct task
}
static void send_sigio_to_task(struct task_struct *p,
- struct fown_struct *fown,
+ struct fown_struct *fown,
int fd,
int reason)
{
- if (!sigio_perm(p, fown, fown->signum))
+ /*
+ * F_SETSIG can change ->signum lockless in parallel, make
+ * sure we read it once and use the same value throughout.
+ */
+ int signum = ACCESS_ONCE(fown->signum);
+
+ if (!sigio_perm(p, fown, signum))
return;
- switch (fown->signum) {
+ switch (signum) {
siginfo_t si;
default:
/* Queue a rt signal with the appropriate fd as its
@@ -442,7 +448,7 @@ static void send_sigio_to_task(struct ta
delivered even if we can't queue. Failure to
queue in this case _should_ be reported; we fall
back to SIGIO in that case. --sct */
- si.si_signo = fown->signum;
+ si.si_signo = signum;
si.si_errno = 0;
si.si_code = reason;
/* Make sure we are called with one of the POLL_*
@@ -454,7 +460,7 @@ static void send_sigio_to_task(struct ta
else
si.si_band = band_table[reason - POLL_IN];
si.si_fd = fd;
- if (!group_send_sig_info(fown->signum, &si, p))
+ if (!group_send_sig_info(signum, &si, p))
break;
/* fall-through: fall back on the old plain SIGIO signal */
case 0:
next prev parent reply other threads:[~2009-06-16 22:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4A36532E.3050006@redhat.com>
[not found] ` <20090615174544.GA10467@redhat.com>
[not found] ` <4A36E555.80206@redhat.com>
[not found] ` <20090616183829.GA10027@redhat.com>
[not found] ` <alpine.LFD.2.01.0906161224110.3282@localhost.localdomain>
2009-06-16 20:07 ` [PATCH] shift current_cred() from __f_setown() to f_modown() Oleg Nesterov
2009-06-16 20:17 ` David Howells
2009-06-16 20:21 ` Linus Torvalds
2009-06-16 21:00 ` Oleg Nesterov
2009-06-16 22:56 ` James Morris
[not found] ` <20090616204941.GB28663@redhat.com>
[not found] ` <alpine.LFD.2.01.0906161433270.16802@localhost.localdomain>
[not found] ` <20090616215103.GA4853@redhat.com>
2009-06-16 22:27 ` Oleg Nesterov [this message]
2009-06-16 23:00 ` [PATCH] send_sigio_to_task: sanitize the usage of fown->signum James Morris
2009-06-16 23:10 ` David Howells
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=20090616222710.GA7620@redhat.com \
--to=oleg@redhat.com \
--cc=dhowells@redhat.com \
--cc=eugene@redhat.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@redhat.com \
--cc=solar@openwall.com \
--cc=torvalds@linux-foundation.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