Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796436225; b=xjOmwoh/bWIMt6mHKj7UPRAcMFxt5Yj7gHzZwAB/cqVm2lmdR4fnVGjJKo+j8LPf1J67 KQJXaNghyuySVKBk/qHntrMDj73/2rt6NROEc3dm9SDdZouABNAP0+BQEgvH7vsZEUfze N0PKBbUzO8G4Sh3Mfy6urrCxh/JD1WASHKInKmyex6+gC1N9apgvNGoUDdKXyXBw0l0GH 85pUNeZ99gucZLBj6FizXkHQty7roGwYs3Gcz2r6/15S93NqChZARsa/n/sF6XXuImVsD 5WuVNV4/puhhxVMILG/Lonj2HXsdozRrBrvePJ9Z+hRBhvOwSQfgkq3OxTdCTFo89+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796436225; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=BJRmyxW+xT6eXpnCigREUwejta0cUdLORGPgPRz/MDU=; b=fwDe5GKjNilqz5ym70MknBRulYvAKrSMqjKQ72JPcuLljXNQ0aiKNnyuCDuVdai7q6m7 Gws+nhK4wZIAQvuuD/55wghHiE55fmk9Cx34u/zR+/yEv+YNEiXzPQ5ry5RqCTaSs0Fx1 UoxvfYRf7MqukPMGVdeD4fExXdsRVYL5La6kDzEEohb52CJz8Jcw3snKQ9psNqeYDypII i4e1uR8Fm6quSrHmRviUmMJVF12UC4NicfFHOtiaKlvPfmH6+cRgfu8pnBbv8EjFT0XUf 8oJ0WMss/4uYcbPvaNDnT20AVvkjSkGfpQ1k0y9n5rHrgfLcXLaFUljz5uUkaFu4B1g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="nyB+n/L4"; arc=none smtp.remote-ip=74.125.229.4 Received: from mail-dy2-f4.google.com (mail-dy2-f4.google.com [74.125.229.4]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B38606A322 for ; Sat, 5 Dec 2026 02:03:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 78B38606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=nyB+n/L4 Received: by mail-dy2-f4.google.com with SMTP id 5a478bee46e88-387362aa672so607837eec.0 for ; Fri, 04 Dec 2026 18:03:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796436224; x=1797041024; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=BJRmyxW+xT6eXpnCigREUwejta0cUdLORGPgPRz/MDU=; b=nyB+n/L4bqGWsh+kzm/kE5kGE3Sx4Thcl6885389kzVKXzZm0N2LRuXqDXOKo8rz6c rK8qtIV8YYhEuZzQvnh/2ssjNmgJAc8gEma8za/SgGUyg0f/bGOTw79vt69MsOzQ0+Gw bueT8tM+IdWjEcDyIrH5DjkDDWCETCNd50hcSixUzLB6rC+f2JxdfrBTqmAE0uSULgNd HaySwan8P5hvauR2mavik+kChfQ2RQ24S0qhBAALjY8X7D+YOQhbMfMnrUIVlaaf9hSK ZfiTf8WPZKyBLXM7JuTzl3zIvgSy5JY+g+fIOP+ehSxrZ6hqfa6nRei3lL901Ht1U5Uc ecLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796436224; x=1797041024; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BJRmyxW+xT6eXpnCigREUwejta0cUdLORGPgPRz/MDU=; b=CeAbROpr/Nm86PFLHjOU/DcoZI67OObEw4e6xp1WjS5NAlOCPj6cfxWgGISFoniRUo ngjxWRgj4Hwxi3hFeHIb8RlxM5NbEGq4SoLJlT0dCaxIq4jaEqeozU6VeP6E/pvH9xeG bxmTk130ObzXw2+VpSeWNMrR+F46yqUiEYJI8H3DL/8SkjMRT++Xg0jA222HyhbtiYVK hXOfHA4g3/vwieXwALHGnGlvm7TFuCeWOntkt5x6+0AV+yWuVq4q8EIrwOLeAIesKwOd 5evmlvAEtHgI5csN67X6wefJPLug3d2SyR9Ffhj/kqP1TD0wCHE/7siiLLHh1EbUEpAA aFng== X-Forwarded-Encrypted: i=1; AL+hErF+0Bp7fSoKL52OOQMMkuNaTlaLaIFMSWaYw6G5Ol0e5V37TEBbBcFWG1N8SNemhvVbHHriYnrWy3BlTNI0@vger.kernel.org X-Gm-Message-State: AB4q+uHIKPoAx4oFMB3pjizX7KoWs+ofR/VYE56Oe+9bIW77zMsetT6j Svv9NMerduOrCiits5zfoBt3St5yS1zzNQyQlgkWSZxrAachAHKHXFGO X-Gm-Gg: AZFdTZfEEkRJQEpkgfv7VAj1jb8UUoW106gTueG2PxhyzasHo4fNFQ0QcTjtvMprCRs cmoH32rNlkctHIJDUiTrcqk+1KSmIsOs1rI4+OYewlU9JcBxUjB7HChCvAti5tUy4YYggCCS9kv j/V5Nm5TCQgM8MqNexckGZ0f4WrQZf0ug2X3zHOmb/OCv/LtCbvulmqWRpdbA3InJlQ4JDCoSZ/ C6Xb/J0fvklMiaWiU3Z3zpZW/PL7N0H2LBX1H1/3QQv21dXwv9t31DK9l6fPew6sJm/eXKFsnaM ec44LiQlEFaUf1t59DkFqJbcl2Y87lLxFfHaxJpgfJkOvqXSs9ETQJ8HnaeI2y65IGbmhoxBPMP 0VfY8g2RoT/bFcjx5xe+Jfwtx2MQRXpz6l0DtLp6OtwPNNpP4rfCgBDCI/jwTkYV0RZA4TjUbX+ N/WSsQyvGS043SmbSjRbkpIofOhsGzUTVTj/H5Qyr9SjaKBU3RY5drR6aBBbyJ880VM8t7EXqIc AUCJtKvm1d940YtLYAttA5xHP94xh2iAhtH+LfPI4qnH1eKJ69IhjULyFxVqQQcWmaRZ33MhCrG DwM2wyXkJdxxcGbw2BnXhfrL+3tfWV8CZsSb2Uinb4giH+HpKqLqJuMwFy4PgPxLTUFB49aqxk2 XkRNR93OpugKzEvBEVns5Q1BCFmOXPIVOeN17qOBN X-Received: by 2002:a05:7301:f23:b0:386:d310:4c1c with SMTP id 5a478bee46e88-3875216e25dmr3690083eec.21.1796436224340; Fri, 04 Dec 2026 18:03:44 -0800 (PST) Received: from localhost.localdomain ([76.33.234.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38752204591sm14411634eec.21.2026.12.04.18.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 18:03:43 -0800 (PST) From: Hungyu Lin To: akpm@linux-foundation.org, brauner@kernel.org Cc: oleg@redhat.com, me@black-desk.cn, adobriyan@gmail.com, jannh@google.com, jack@suse.cz, sforshee@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, dennylin0707@gmail.com Subject: [PATCH v2] proc: also check the opener's capability for oom_score_adj and oom_adj Date: Sat, 5 Dec 2026 02:03:34 +0000 Message-ID: <20261205020334.34417-1-dennylin0707@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit __set_oom_adj() checks CAP_SYS_RESOURCE against the task that calls write(). A task without the capability can open its own /proc//oom_score_adj or /proc//oom_adj and have a privileged process write to that file descriptor, for example a set-user-ID program that inherits it as standard output. The write then lowers the value below oom_score_adj_min, down to OOM_SCORE_ADJ_MIN, which the opener is not allowed to do. The capability of the writer also decides whether the write sets oom_score_adj_min. If the privileged process writes 500 to such a file descriptor, oom_score_adj_min becomes 500 and the opener can no longer lower the value back to 0. Writing 500 itself would have left oom_score_adj_min unchanged. Require the capability from the opener of the file as well as from the writer in both places: check file_ns_capable() in addition to capable() before lowering the value, and the opener's credentials in addition to has_capability_noaudit(), also without auditing, before setting oom_score_adj_min. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Hungyu Lin --- Changes in v2: - Also require the opener's capability before setting oom_score_adj_min (Oleg). - The checks that refuse the write keep capable() and file_ns_capable(), so a refused write is still audited. v1: https://lore.kernel.org/all/20261126045222.20770-1-dennylin0707@gmail.com/ fs/proc/base.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index e6d54193b9f5..c94668dcb9db 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1090,16 +1090,23 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) { struct mm_struct *mm = NULL; struct task_struct *task; + bool update_min; int err = 0; task = get_proc_task(file_inode(file)); if (!task) return -ESRCH; + update_min = !legacy && + !security_capable(file->f_cred, &init_user_ns, CAP_SYS_RESOURCE, + CAP_OPT_NOAUDIT) && + has_capability_noaudit(current, CAP_SYS_RESOURCE); + mutex_lock(&oom_adj_mutex); if (legacy) { if (oom_adj < task->signal->oom_score_adj && - !capable(CAP_SYS_RESOURCE)) { + (!file_ns_capable(file, &init_user_ns, CAP_SYS_RESOURCE) || + !capable(CAP_SYS_RESOURCE))) { err = -EACCES; goto err_unlock; } @@ -1112,7 +1119,8 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) task_pid_nr(task)); } else { if ((short)oom_adj < task->signal->oom_score_adj_min && - !capable(CAP_SYS_RESOURCE)) { + (!file_ns_capable(file, &init_user_ns, CAP_SYS_RESOURCE) || + !capable(CAP_SYS_RESOURCE))) { err = -EACCES; goto err_unlock; } @@ -1136,7 +1144,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) } task->signal->oom_score_adj = oom_adj; - if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) + if (update_min) task->signal->oom_score_adj_min = (short)oom_adj; trace_oom_score_adj_update(task); @@ -1155,7 +1163,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) task_lock(p); if (!p->vfork_done && process_shares_mm(p, mm)) { p->signal->oom_score_adj = oom_adj; - if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) + if (update_min) p->signal->oom_score_adj_min = (short)oom_adj; } task_unlock(p); base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7 -- 2.43.0