Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398985; b=UAdI1evmURZ/RrLS8IMk3C2Z3IRxnnKouQE6wNZnDVr0rnzWgntbRCupDwyHUhZTxQ5v E/kgzCLny/Rka8ILLtDj7aL7xa9ZMK5tDYCyTBNWJF+SWEF68PY6fbRI5diZ+Znl1gc6Z G388IAPBaMCpqJ2VtFCoGpH14XLp9H8FOrjobJXMUYcfeqmQ6wI1uqaUd3KmKgwyDDOQk 61myb95SCZWG5DO0Y36PAOF+UVaY49FFk8TgW7hXL40UBRixLzr3yV/u72Vg/4BCPIIx7 4gDuEguUi7AKuJ+AIn3ES2AYwnK6W/JCCYQc9CjHz8TtrCGqV+D7ru7GfuOjHip8jzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398985; 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=/ZCw/LVhdZt4ganSm3xLQUasLPHlqlUubqO6Xj/kjjU=; b=q5gCkLywU1sNjn7uA2PwasC2J39+v4TlPPArSyfaiSa0/TJ0m4QXbO0mGb4KgjzEq7Eg RRzqT2Yh2rjWg7ZJvINlFRlBqPA/gfTtf4N31GHPTpv9o89PlJFpLLOPY+gbA8TZ205s1 CIghQ2ba6y0QIfYqvLd4+pkUWwqghsMlSw03C5FZbdfhs59WTKqZTUDgcdJUuYWuGIe7R Um/1nHRGv9n8/sH0M1FxFd/dtpAPR0ShxI/X+jdtMgCx/mpQpFr+2ipyCCUO6Lo4kL5+G t4MvoFviHL3TsWjGJ0rxrOerkCZPnDe8r367nccw8OH/10ruIUEZxkiaMEyz/A0VBUg== 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=K5NNeqJJ; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 2B80A606A68F for ; Fri, 4 Dec 2026 15:43:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B80A606A68F 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=K5NNeqJJ Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4a214c5c4c0so10621345e9.3 for ; Fri, 04 Dec 2026 07:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796398984; x=1797003784; 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=/ZCw/LVhdZt4ganSm3xLQUasLPHlqlUubqO6Xj/kjjU=; b=K5NNeqJJcECozUOrXJT1OAzYI9T266wqFXGsNEI0bH1xij1XD5N5fPMTrw8b7HXe5G +9lJH3uahWHRy0WSe7lxzOwODUGnHCkymcLzmhNoW/LnjX5Ty1BZKgDWWTUZeeAWa3hX 4+IGDh6PAw+xrjTxrds9h/Srx9pTEByuLX+JcqGNB31yCkZKobM4g8iL865w2y9KvpGV rDT3DmqP1i+bpmQ3Ep/moMZA0OZZrZ3mkt//VwCLn54mOkC6jI1v8DSKnxAEkbW5NoH9 DY/QJG7uMZ3yu7G9F4CaCS08foJTmgxnWkhOzoJa0ykpqTZMHYHgFqkGCWr1PQXBQdsn 6+eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398984; x=1797003784; 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=/ZCw/LVhdZt4ganSm3xLQUasLPHlqlUubqO6Xj/kjjU=; b=dXtUDwNJhZ/L8tkCWzOofnJemE3XjTHWefRlT65R4vcQ2BVWKoOi7i6wzKQVI2EL2K 1WNkz3ZA5xbRlriVlDVOwj677pPSUBhTkwAGoxBs+0VjnS/sUceHHcKnRZg0wcaxpuuh JZSOoL5EN9qhdFDcZt2MhnArfi1pxBGqJmjV6EjaoaCvYetUUGyTlso8RTEW0rp+2QZ6 JwEHlC9GY2IG0G42zwW3J7nbc5djfP2c+9MOvOXUwMK7Up35iz0YOClKtLGcXzC1qvsU 74FBbK/WX/tRpXAnVZFoYo7ToIGL/4iJE6cYmp9tYIiXxOvs+OIYVt1InBWjWX4rX5nd KW6w== X-Forwarded-Encrypted: i=1; AL+hErFRHKKgt/A43dPQhPZ0gr4bu2V0BIJbPn4SxyXLEO0C4jJjbIse45hUzllJc2QFB8cED8Q=@vger.kernel.org X-Gm-Message-State: APuU4Z/HyXF7xViUiSoFSpa/vhO5lFNHL8Zj5LV4HVi2lJ7WdaCqkecT 0g60TptACUAh+zwrzzYaQGvyfn/DrUKv0NCutn15Zbn19/tPVU9T8Rrq X-Gm-Gg: AZFdTZfq4k36UtDV3677yIb5VVx77GOPSsGQoQk5MW+1R6fxajcyBTNepxze7UUQqQc M9Av5ZTuEevV6G0j8mg4zXS3QYArc/9pNjVDlo7X1PA6BiHbo8RVZfpJRhRKUWNdIRHEMtWmOED 2Hno1tYL9FXHuUyq1A5+8jeOWfGvdbjHdKEumcrxzLFZhKHgF7u3YtiOTyOpL9OYYX+TxvcC/ri 8tL/xX+EsprfQOwVX3gOwL3oPbEajVIQhOWZOwWYHqtD5HAVq17eB6+Cr5dAY9M/eke3sS53R2j Y08dvIuc1BsznYGS9DMQIE1feWe8K+wrjTe/ioGcKanYrftgCuXCnLck4uDsYNIhWZMrHDec2mZ 4lWNHGtxDJkqGXx7qxTB5tKqPkO27WyRPIUtXxcZ61ONdK8ygMQ/+12fY6spH1oFLyJqqW1Rfot wWwX10YIB49RFoIOpgtcDWA6qOw8ZY6CzngddbFLGJDAZ7UmLgynPS0uq3iFsCZqU+kLOXa0bfV vSOuwIgJgB8p1MaF/DakF5FSdedwzz41GX8qB0syUWpJ2uLWso2ENnDPZd+4KE6ABvUWfiMiqKd aMiaumf0weWJAWcHEXpC8hek4hnw+DWWuWTAbLJqFKCaL+4= X-Received: by 2002:a05:600c:34d2:b0:4a1:fae5:f2e2 with SMTP id 5b1f17b1804b1-4bbeb6ef054mr49936735e9.4.1796398983474; Fri, 04 Dec 2026 07:43:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:43:03 -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 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked Date: Fri, 4 Dec 2026 15:54:33 +0000 Message-ID: <20261204155438.1413411-4-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 are allowed on every sleepable LSM hook. Both take iint->mutex in __ima_inode_hash(). IMA itself takes iint->mutex before the inode lock: process_measurement() holds it and locks the inode to appraise the file. IMA also holds it while it sets security.ima in ima_fix_xattr() and ima_update_xattr(). So a program which calls the helpers on a hook called with the inode locked can deadlock. On inode_setxattr, inode_removexattr, inode_setattr, inode_unlink, path_chmod or path_chown it waits for iint->mutex, while a concurrent open of the file holds it and waits for the inode lock. On inode_post_setxattr it may wait for iint->mutex which the task itself holds when IMA sets security.ima. These hooks are in d_inode_locked_hooks. Don't allow the helpers there. Fixes: 27672f0d280a ("bpf: Add a BPF helper for getting the IMA hash of an inode") Signed-off-by: Anton Protopopov --- kernel/bpf/bpf_lsm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index 608d188ffe0e..6c79d4786f67 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -207,6 +207,7 @@ 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) && + !bpf_lsm_has_d_inode_locked(prog) && !btf_id_set_contains(&bpf_ima_inode_hash_denied_hooks, prog->aux->attach_btf_id); } -- 2.43.0