Skip to content

Commit 9e05e5c

Browse files
rgushchinakpm00
authored andcommitted
signal: restore the override_rlimit logic
Prior to commit d646969 ("Reimplement RLIMIT_SIGPENDING on top of ucounts") UCOUNT_RLIMIT_SIGPENDING rlimit was not enforced for a class of signals. However now it's enforced unconditionally, even if override_rlimit is set. This behavior change caused production issues. For example, if the limit is reached and a process receives a SIGSEGV signal, sigqueue_alloc fails to allocate the necessary resources for the signal delivery, preventing the signal from being delivered with siginfo. This prevents the process from correctly identifying the fault address and handling the error. From the user-space perspective, applications are unaware that the limit has been reached and that the siginfo is effectively 'corrupted'. This can lead to unpredictable behavior and crashes, as we observed with java applications. Fix this by passing override_rlimit into inc_rlimit_get_ucounts() and skip the comparison to max there if override_rlimit is set. This effectively restores the old behavior. Link: https://lkml.kernel.org/r/20241104195419.3962584-1-roman.gushchin@linux.dev Fixes: d646969 ("Reimplement RLIMIT_SIGPENDING on top of ucounts") Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev> Co-developed-by: Andrei Vagin <avagin@google.com> Signed-off-by: Andrei Vagin <avagin@google.com> Acked-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Alexey Gladkov <legion@kernel.org> Cc: Kees Cook <kees@kernel.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b8ee299 commit 9e05e5c

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

include/linux/user_namespace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ static inline long get_rlimit_value(struct ucounts *ucounts, enum rlimit_type ty
141141

142142
long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v);
143143
bool dec_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v);
144-
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type);
144+
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
145+
bool override_rlimit);
145146
void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type);
146147
bool is_rlimit_overlimit(struct ucounts *ucounts, enum rlimit_type type, unsigned long max);
147148

kernel/signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags,
419419
*/
420420
rcu_read_lock();
421421
ucounts = task_ucounts(t);
422-
sigpending = inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING);
422+
sigpending = inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING,
423+
override_rlimit);
423424
rcu_read_unlock();
424425
if (!sigpending)
425426
return NULL;

kernel/ucount.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type)
307307
do_dec_rlimit_put_ucounts(ucounts, NULL, type);
308308
}
309309

310-
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type)
310+
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
311+
bool override_rlimit)
311312
{
312313
/* Caller must hold a reference to ucounts */
313314
struct ucounts *iter;
@@ -320,7 +321,8 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type)
320321
goto dec_unwind;
321322
if (iter == ucounts)
322323
ret = new;
323-
max = get_userns_rlimit_max(iter->ns, type);
324+
if (!override_rlimit)
325+
max = get_userns_rlimit_max(iter->ns, type);
324326
/*
325327
* Grab an extra ucount reference for the caller when
326328
* the rlimit count was previously 0.

0 commit comments

Comments
 (0)