From nobody Sun Nov 24 22:38:24 2024 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3E1B1CC8A8 for ; Thu, 31 Oct 2024 20:05:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730405104; cv=none; b=Rp8HCkxY6lIZ1eI8NoOzeMJDUXrtqcmJlv12472MUabEfjSBdiepzoDK4jCY8yJZ1Fs5Lpx767Os+AOkDgYATMP23MZ5B7opD1qOrL0eeisWtHotyB2y3Z1p1LBXyf7fFHJ14YOkXuoCGnTYBNJ2ZbtJFsGmt1CdQdOSAljGd9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730405104; c=relaxed/simple; bh=fmvdPe7Xqvw35e8475LMA7hTK57Z/W159GPPmX2ajhE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EATjnzNBwmlJUSq6WIf6c8CSUyD4bUr5P+y+vk+qzeg8xYXXrr+2wYAHsm9Nm7YihdfZXlydqLXX+dveC3g/YRfIbppX3ZFI5lQHn5iQRjl6nTuIzppVkIGE6CjW/0oB5L4vZ+D9TOc3bDdr3mL5IbVA0M2xX/U1+5elDV/WPTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=MQkQ4vpj; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="MQkQ4vpj" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1730405099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=A7L9CUWVM54y7lE4x9OSE5ACsKWIejbvvXMBTey286M=; b=MQkQ4vpjYQiUThJMXLRIiylukdNwdyqOgJtdP/0yxAInpg+9AIBY2k4JorbVzqwAoT6r4r VzVn7LHW8uqOh/0MxrSCQrZRerwmZ8vY9evfC3VV5jSwLdAsFCT/lXhTIt5nyBcLKwQSjR RAQJFloQgjZt5ZvD9VXfH9gopfnDRp0= From: Roman Gushchin To: linux-kernel@vger.kernel.org Cc: Roman Gushchin , Andrei Vagin , Kees Cook , "Eric W. Biederman" , Alexey Gladkov , stable@vger.kernel.org Subject: [PATCH] signal: restore the override_rlimit logic Date: Thu, 31 Oct 2024 20:04:38 +0000 Message-ID: <20241031200438.2951287-1-roman.gushchin@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Prior to commit d64696905554 ("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. Fixes: d64696905554 ("Reimplement RLIMIT_SIGPENDING on top of ucounts") Signed-off-by: Roman Gushchin Co-developed-by: Andrei Vagin Signed-off-by: Andrei Vagin Cc: Kees Cook Cc: "Eric W. Biederman" Cc: Alexey Gladkov Cc: --- include/linux/user_namespace.h | 3 ++- kernel/signal.c | 3 ++- kernel/ucount.c | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 3625096d5f85..7183e5aca282 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -141,7 +141,8 @@ static inline long get_rlimit_value(struct ucounts *uco= unts, enum rlimit_type ty =20 long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, lo= ng v); bool dec_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, lo= ng v); -long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type= ); +long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type, + bool override_rlimit); void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type= ); bool is_rlimit_overlimit(struct ucounts *ucounts, enum rlimit_type type, u= nsigned long max); =20 diff --git a/kernel/signal.c b/kernel/signal.c index 4344860ffcac..cbabb2d05e0a 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -419,7 +419,8 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t = gfp_flags, */ rcu_read_lock(); ucounts =3D task_ucounts(t); - sigpending =3D inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); + sigpending =3D inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, + override_rlimit); rcu_read_unlock(); if (!sigpending) return NULL; diff --git a/kernel/ucount.c b/kernel/ucount.c index 16c0ea1cb432..046b3d57ebb4 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -307,7 +307,8 @@ void dec_rlimit_put_ucounts(struct ucounts *ucounts, en= um rlimit_type type) do_dec_rlimit_put_ucounts(ucounts, NULL, type); } =20 -long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type) +long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type, + bool override_rlimit) { /* Caller must hold a reference to ucounts */ struct ucounts *iter; @@ -316,7 +317,7 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, en= um rlimit_type type) =20 for (iter =3D ucounts; iter; iter =3D iter->ns->ucounts) { long new =3D atomic_long_add_return(1, &iter->rlimit[type]); - if (new < 0 || new > max) + if (new < 0 || (!override_rlimit && (new > max))) goto unwind; if (iter =3D=3D ucounts) ret =3D new; --=20 2.47.0.163.g1226f6d8fa-goog