From patchwork Mon Nov 25 10:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13884786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23B24D3B7FF for ; Mon, 25 Nov 2024 10:40:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CAB66B0082; Mon, 25 Nov 2024 05:40:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 27AFE6B0083; Mon, 25 Nov 2024 05:40:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1435A6B0085; Mon, 25 Nov 2024 05:40:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EB6936B0082 for ; Mon, 25 Nov 2024 05:40:30 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5CBD880570 for ; Mon, 25 Nov 2024 10:40:30 +0000 (UTC) X-FDA: 82824273252.08.3932A15 Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) by imf22.hostedemail.com (Postfix) with ESMTP id 409E2C0010 for ; Mon, 25 Nov 2024 10:40:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=seltendoof.de header.s=2023072701 header.b=Mdb4xOeL; spf=pass (imf22.hostedemail.com: domain of cgoettsche@seltendoof.de designates 168.119.48.163 as permitted sender) smtp.mailfrom=cgoettsche@seltendoof.de; dmarc=pass (policy=reject) header.from=seltendoof.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732531224; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uXJbjp9TEMr3wvQ+2vZpGMNVJ7tkSZTdw7fouyXGnz0=; b=tGPKbs/z3xAabOoXOt5b+9uYG7EZv2/LV7X0zHylloYQir5wsIjoMPT36nSdzywcOAAz4b hsH1ccIVErn5ksyzDYVLW3iRWKOuvcIadMoXSOZ4gD6GBclOcobX6AJcgCl0EFe/MQfFzU aP32iP6ZfBm5e27TM1bUNa+wPf4uf6Y= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=seltendoof.de header.s=2023072701 header.b=Mdb4xOeL; spf=pass (imf22.hostedemail.com: domain of cgoettsche@seltendoof.de designates 168.119.48.163 as permitted sender) smtp.mailfrom=cgoettsche@seltendoof.de; dmarc=pass (policy=reject) header.from=seltendoof.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732531224; a=rsa-sha256; cv=none; b=0+hm/7SxDgRTvVrPmTS1vOE4d2gl39HdzyTp6cQEfuSt6X+u/ySYI8UzUy6jg+1KeH8db/ ABpgPhed16cLIZs6zfA4Sz03VYy87Eg8bjkBoHpTH49brTXKmu2UvAAoF0zmjjTTQcj7ZB iZ3VkLKQCFxPiTbNtscVkxEltwZLuRQ= From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1732531225; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uXJbjp9TEMr3wvQ+2vZpGMNVJ7tkSZTdw7fouyXGnz0=; b=Mdb4xOeLmRxHgooUx3JOijX3+LMSlj4GRxvTHEPWd1og60SnG27YZkYD2Ceyjx+7B333QM ZyLgYWtMHFmpAS4jQ0VS7zdfJq9cQ9qMI1VXAh2OJqLOjuiladwhEQxhs5QkMpM4d+88/j YY61kw6/zF9K2N5hNSbT40SYIj6CvC8CdzV+bU9xHoZrZXIDj3azO4Pssrl2ovpBnSmIzD Mv0etwsaWtD04zX2lsGfDFSxo61zYM7APvut1Mn8G6dTOzCPF4BW7lPtuQElc1iacTmQXf 8qW38Pn8ScwYATLiIG45X5y8yS2CZ7A99XQg1RtL/r9qa9EeW8r4/TzXlS2Ylw== To: linux-security-module@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= , Muchun Song , Serge Hallyn , Julia Lawall , Nicolas Palix , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cocci@inria.fr Subject: [PATCH 04/11] hugetlbfs: reorder capability check last Date: Mon, 25 Nov 2024 11:39:56 +0100 Message-ID: <20241125104011.36552-3-cgoettsche@seltendoof.de> In-Reply-To: <20241125104011.36552-1-cgoettsche@seltendoof.de> References: <20241125104011.36552-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 409E2C0010 X-Stat-Signature: hozeyubg8b7ifno9exegu4kbrtqcedx7 X-Rspam-User: X-HE-Tag: 1732531224-878721 X-HE-Meta: U2FsdGVkX18/8YLdVyV3vnFEey5zPK5FULk3DROEzF3L5BJX3LRFsR2Lqx4/bc6aoLkenRqbzS/zcv2/yhq9JAY9OHcITZ1pLl31w1SQeIqUqNsRpnBKBTt6mxvitIXLw8t70dNrSmTsccecF4/007pC15VP5Knlr1ymMK8LVHZ7nyCouLeDcDsRph1nnrF7VckBPo2lZI+hvn+JdclfnffzDvLgx9r9qx765nivgGfIkmuxmjUiibBTUBGoUMqJCDfrBbayQbcCokonFiJx/1CAe5ajX990Zj4m5l8qGdfgNkLT+ARULYgJshXkYwM0EyP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np/bJSCTv1SS4+s6mqHZqZXYAO7sggLLQ8UcDQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Christian Göttsche capable() calls refer to enabled LSMs whether to permit or deny the request. This is relevant in connection with SELinux, where a capability check results in a policy decision and by default a denial message on insufficient permission is issued. It can lead to three undesired cases: 1. A denial message is generated, even in case the operation was an unprivileged one and thus the syscall succeeded, creating noise. 2. To avoid the noise from 1. the policy writer adds a rule to ignore those denial messages, hiding future syscalls, where the task performs an actual privileged operation, leading to hidden limited functionality of that task. 3. To avoid the noise from 1. the policy writer adds a rule to permit the task the requested capability, while it does not need it, violating the principle of least privilege. Signed-off-by: Christian Göttsche --- fs/hugetlbfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a4441fb77f7c..e4f6790c1638 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1508,7 +1508,7 @@ static int can_do_hugetlb_shm(void) { kgid_t shm_group; shm_group = make_kgid(&init_user_ns, sysctl_hugetlb_shm_group); - return capable(CAP_IPC_LOCK) || in_group_p(shm_group); + return in_group_p(shm_group) || capable(CAP_IPC_LOCK); } static int get_hstate_idx(int page_size_log)