Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398984; b=pMouOAVPJ5mSEdB9s8O9QqdAY/PDb+42KYLcbwm92N7e1G0K+eNNxrBLZ3QWDjyFd4gM CXaP7+HMndORB5/ZjoFB9Vm3DArReEmwUaHip7JtW5Fc6ncWZWEWQyGNInP+qmqddH7c0 bpXvODKFtrtwIXiyueb/5WNocWG2jC84ES/30V5VM/BJqW6iaH/jzfKSy5DUXIQJ4iYHy VxMgHNrWNJh7PN74vFDUChPX44V1DDS9fhMOrZLTnqTyUGIA2XjpQXstjfbEDZ9G5P6Ve xZome97vlXg4WB5FZAkv7w4pQ4R4fxNcbLvm7B0YcHgkhzN6aLxGYGBb5WplMUQN78A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398984; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=jQjtcxkuG9ynMIzikR5hS7WsoX0qsyZd2qLNHtkaFso=; b=ql9vfp2iBumgFG/1+BAlRL23qFWshwOR/JZXd5RRrIt/iRgfjwLK4kMFZtn8nGIY2mfg 0Hic2/Nm9vbpkUjgrIS2UQzEPu8AZ6gl68DG837b/qZckjjLCtQUIriY71Bs7T9+E/bYZ qdpKMtFpjQc+CNtFAk6FJzy8WigTkFmXiW7SPa6Pbr1JX1yappDGLX0FTqEb9fpVOnD/v N3ImWz4yWTKGrs/cegXL/TP5XWPeWSlNnqSgmQ+3u7P5JMkcZ8mAZWUdlWk+vPnAIlf0A 3GAUDH2qTdi5ired3W9lm6jgXW2adMZ4lXhR4LRIZcQGJbn5fVxUV9+TkDvKOARazrw== 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=GVWWPD+O; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 CB170606A693 for ; Fri, 4 Dec 2026 15:43:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CB170606A693 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) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GVWWPD+O Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so7630085e9.0 for ; Fri, 04 Dec 2026 07:43:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796398982; x=1797003782; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jQjtcxkuG9ynMIzikR5hS7WsoX0qsyZd2qLNHtkaFso=; b=GVWWPD+OgrIwWgiLVMiQrumiwEDnYCcfa5NCY13tq5HiCIorgwY8dFk1kNxh1oW/Ha H10X3MpmGREeLYlFKIIPhOd7GQpFh30R/qiSnk0qB+WvErereTio2YX7We2CPQFu3icD G/NFcGq/IC7Xv+MkfFzcBKvC6o2vR7qgQdINhxyMuBYH0KEXr5lA9hmKwE42nBgnmtF2 0OmEr5E4P7HK+O8G0FEFM84ryJTaFa3Qltmq4vayknRNReMb7R2PseAAu5RXd5nVKhaf CV1m8wXInJxbc5VxsQXTj5E4JLLI46SBlVzVA2r8wmeXVxyzLZDynxcBBN9p6ca+XwOD RmXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398982; x=1797003782; h=content-transfer-encoding:mime-version:references:in-reply-to :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=jQjtcxkuG9ynMIzikR5hS7WsoX0qsyZd2qLNHtkaFso=; b=H4csuwbhBRzZDgp7W+MFlAyLG8pSLZGCXAr117tkQ4bcvxkUkeh3lFtnkRWvXHdSfE KZMHnNuhB3C7N7gDolKiqMewUAlfETVnErfiY6e4AwU1KAxHmCrP/anJ1wRC+pzh5rhG xvjabpAe5qcvDJJvvDory3L4Pm75nE88uRHg2RvCtyW3jXOgljKZ7/g+py2OjorSQwDO gz+F8hzndadwMdptkUzn1EiGjWPokSJLoROM/nR4iV3givi3ltiZC2MuZVoHNTl8AzB9 H/X3UOK/dBj40Q2JoRtlPVO/sZP1KfQlv32/CauoXtGigUD3q2OVrUWn65aRAVO+LCns chNA== X-Forwarded-Encrypted: i=1; AL+hErEwoLfDEpyCP/23RRW0XDc8szTmFWYN/0+fST8jfUF0/QM9K8ZYaBolSry+B9p+nykDplg=@vger.kernel.org X-Gm-Message-State: APuU4Z9MFaIGwNvpyDG9ynoAGWBKNi5jWM0Apj9RN4L+HgiPtA0k3i4W huFf+Tl4U+LFAN/QY9YnUx3CmOZN838WqEoGjFPazmZMvF6+o9L/Epug X-Gm-Gg: AZFdTZfViIoPaQ+LbHgCeVLysRUqj6OPJ9G/3Qy/QIoQo+MfJ/oO/fWOT23hw4l3hms uLiBV2qg1nNSGX1jF/oqnn4wLcpFbssWsJEqrtooSVCBRutT1A9sqi0W0yq9TOVN5hPJ079/n/L fFL16mwSNgHy9/22/+habMQ+NoLJyePhjbmBrqblPpwcIE61L1PkSGiliGb2iKT7PGQ2C0FXtv6 sQSrJ8Zr0Hsntml6jmvovu++9nqU+LVYOghqcpeh2CL9787ApKAGgly1+x59NPqUWiT7R90eEJ3 yqa/FeqFcmV88BVjXdNTE8e60BiG+JaA9AR09lHDwchCi7J4AMpp2rSyHN7gdC8ZbhJePf7cDlc 81dLwR5AGX2SdJOVuhGu0Z5s/xjn2+it3oEyotLmloCX8JUAOnb6Eo/cuDnQhD9pLVuvr3CbOBs BEPGXCPTPeJ94/u4cb6kUjMOUOY9LFijnZOL9iTyyfD5AskrkY7Y8riJvmV3HfrzoIrw4O6i5jP m+aG/YqRsmjj/54KRsLWArE7uQsaJmuHJkOMYur2r/IkX5TKkTcFJxzteNnlSTGThcC0ulX0TaD wYxbPZp1zGxYUSMQtTf7Q2q1k/M0UqtgNdesR2qRcG7lHxMxUEPEk+EwPknQ935/SPjq X-Received: by 2002:a05:600c:e54a:10b0:4bb:7757:fe58 with SMTP id 5b1f17b1804b1-4bbeb8d4973mr31288105e9.19.1796398982113; Fri, 04 Dec 2026 07:43:02 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea25ce51sm63147535e9.5.2026.12.04.07.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:43:01 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , KP Singh , Matt Bobrowski , Alexander Viro , Christian Brauner , Jan Kara , Mimi Zohar , Roberto Sassu , bpf@vger.kernel.org, linux-integrity@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 2/6] bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr Date: Fri, 4 Dec 2026 15:54:32 +0000 Message-ID: <20261204155438.1413411-3-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204155438.1413411-1-a.s.protopopov@gmail.com> References: <20261204155438.1413411-1-a.s.protopopov@gmail.com> X-Mailing-List: bpf@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 The bpf_ima_inode_hash() and bpf_ima_file_hash() helpers take iint->mutex in __ima_inode_hash(). IMA takes iint->mutex before the inode lock in process_measurement(). So a program which calls them with the inode locked can deadlock against a concurrent open of the file. The inode_getxattr and inode_getattr hooks are sometimes called with the inode locked. EVM reads xattrs with vfs_getxattr() to update security.evm from the post setxattr, removexattr and setattr hooks, which run with the inode locked. And nfsd_setattr() locks the inode before fh_fill_pre_attrs() calls vfs_getattr(). IMA also verifies security.evm with iint->mutex held and EVM reads the xattrs with vfs_getxattr(). So a program on inode_getxattr can wait for the mutex which its own task holds. The hooks can't go to d_inode_locked_hooks as most callers don't hold the lock. Don't allow the helpers on them. Fixes: 423f16108c9d ("bpf: Augment the set of sleepable LSM hooks") Signed-off-by: Anton Protopopov --- kernel/bpf/bpf_lsm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index 1e2acb7581e7..608d188ffe0e 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -198,9 +198,17 @@ BPF_CALL_3(bpf_ima_inode_hash, struct inode *, inode, void *, dst, u32, size) return ima_inode_hash(inode, dst, size); } +/* Hooks which may be called with the inode locked or with iint->mutex held */ +BTF_SET_START(bpf_ima_inode_hash_denied_hooks) +BTF_ID(func, bpf_lsm_inode_getattr) +BTF_ID(func, bpf_lsm_inode_getxattr) +BTF_SET_END(bpf_ima_inode_hash_denied_hooks) + static bool bpf_ima_inode_hash_allowed(const struct bpf_prog *prog) { - return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id); + return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id) && + !btf_id_set_contains(&bpf_ima_inode_hash_denied_hooks, + prog->aux->attach_btf_id); } BTF_ID_LIST_SINGLE(bpf_ima_inode_hash_btf_ids, struct, inode) -- 2.43.0