From: Walt Drummond <walt@drummond.us>
To: Thomas Gleixner <tglx@linutronix.de>,
John Johansen <john.johansen@canonical.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: linux-kernel@vger.kernel.org, Walt Drummond <walt@drummond.us>,
linux-security-module@vger.kernel.org
Subject: [RFC PATCH 3/8] signals: Use a helper function to test if a signal is a real-time signal.
Date: Mon, 3 Jan 2022 10:19:51 -0800 [thread overview]
Message-ID: <20220103181956.983342-4-walt@drummond.us> (raw)
In-Reply-To: <20220103181956.983342-1-walt@drummond.us>
Rather than testing against SIGRTMIN/SIGRTMAX directly, use this
helper to determine if a signal is a real-time signal.
Signed-off-by: Walt Drummond <walt@drummond.us>
---
include/linux/signal.h | 8 ++++++++
kernel/signal.c | 6 +++---
kernel/time/posix-timers.c | 3 ++-
security/apparmor/ipc.c | 4 ++--
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/include/linux/signal.h b/include/linux/signal.h
index c66d4f520228..a730f3d4615e 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -53,6 +53,14 @@ enum siginfo_layout {
enum siginfo_layout siginfo_layout(unsigned sig, int si_code);
+/* Test if 'sig' is a realtime signal. Use this instead of testing
+ * SIGRTMIN/SIGRTMAX directly.
+ */
+static inline int realtime_signal(unsigned long sig)
+{
+ return (sig >= SIGRTMIN) && (sig <= SIGRTMAX);
+}
+
/*
* Define some primitives to manipulate sigset_t.
*/
diff --git a/kernel/signal.c b/kernel/signal.c
index 94b1828ae973..a2f0e38ba934 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1065,7 +1065,7 @@ static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
static inline bool legacy_queue(struct sigpending *signals, int sig)
{
- return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
+ return !realtime_signal(sig) && sigismember(&signals->signal, sig);
}
static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t,
@@ -1108,7 +1108,7 @@ static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struc
* make sure at least one signal gets delivered and don't
* pass on the info struct.
*/
- if (sig < SIGRTMIN)
+ if (!realtime_signal(sig))
override_rlimit = (is_si_special(info) || info->si_code >= 0);
else
override_rlimit = 0;
@@ -1144,7 +1144,7 @@ static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struc
break;
}
} else if (!is_si_special(info) &&
- sig >= SIGRTMIN && info->si_code != SI_USER) {
+ realtime_signal(sig) && info->si_code != SI_USER) {
/*
* Queue overflow, abort. We may abort if the
* signal was rt and sent by user using something
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 1cd10b102c51..6afb98eadd1d 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -442,7 +442,8 @@ static struct pid *good_sigevent(sigevent_t * event)
fallthrough;
case SIGEV_SIGNAL:
case SIGEV_THREAD:
- if (event->sigev_signo <= 0 || event->sigev_signo > SIGRTMAX)
+ /* Signal 0 is a valid signal, just not here. */
+ if (!valid_signal(event->sigev_signo) || event->sigev_signo == 0)
return NULL;
fallthrough;
case SIGEV_NONE:
diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
index fe36d112aad9..8149b989b665 100644
--- a/security/apparmor/ipc.c
+++ b/security/apparmor/ipc.c
@@ -130,9 +130,9 @@ int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
static inline int map_signal_num(int sig)
{
- if (sig > SIGRTMAX)
+ if (!valid_signal(sig))
return SIGUNKNOWN;
- else if (sig >= SIGRTMIN)
+ else if (realtime_signal(sig))
return sig - SIGRTMIN + SIGRT_BASE;
else if (sig < MAXMAPPED_SIG)
return sig_map[sig];
--
2.30.2
next prev parent reply other threads:[~2022-01-03 18:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-03 18:19 [RFC PATCH 0/8] signals: Support more than 64 signals Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 1/8] signals: Make the real-time signal system calls accept different sized sigset_t from user space Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 2/8] signals: Put the full signal mask on the signal stack for x86_64, X32 and ia32 compatibility mode Walt Drummond
2022-01-03 18:19 ` Walt Drummond [this message]
2022-01-03 18:19 ` [RFC PATCH 4/8] signals: Remove sigmask() macro Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 5/8] signals: Better support cases where _NSIG_WORDS is greater than 2 Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 6/8] signals: Round up _NSIG_WORDS Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 7/8] signals: Add signal debugging Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 8/8] signals: Support BSD VSTATUS, KERNINFO and SIGINFO Walt Drummond
2022-01-04 7:27 ` Greg Kroah-Hartman
2022-01-07 21:48 ` Arseny Maslennikov
2022-01-07 21:52 ` Walt Drummond
2022-01-07 22:39 ` Arseny Maslennikov
2022-01-08 14:38 ` Arseny Maslennikov
2022-01-03 18:48 ` [RFC PATCH 0/8] signals: Support more than 64 signals Al Viro
2022-01-04 1:00 ` Walt Drummond
2022-01-04 1:16 ` Al Viro
2022-01-04 1:49 ` Al Viro
2022-01-04 18:00 ` Eric W. Biederman
2022-01-04 20:52 ` Theodore Ts'o
2022-01-04 21:33 ` Walt Drummond
2022-01-04 22:05 ` Eric W. Biederman
2022-01-04 22:23 ` Theodore Ts'o
2022-01-04 22:31 ` Walt Drummond
2022-01-07 19:29 ` Arseny Maslennikov
2022-05-19 12:27 ` Pavel Machek
2022-01-07 19:19 ` Arseny Maslennikov
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=20220103181956.983342-4-walt@drummond.us \
--to=walt@drummond.us \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=tglx@linutronix.de \
/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).