From mboxrd@z Thu Jan 1 00:00:00 1970 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 2107FD30011 for ; Fri, 18 Oct 2024 14:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86FA26B0089; Fri, 18 Oct 2024 10:56:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 846766B008A; Fri, 18 Oct 2024 10:56:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E576B008C; Fri, 18 Oct 2024 10:56:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4ECB96B0089 for ; Fri, 18 Oct 2024 10:56:11 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 06F6AA9FEE for ; Fri, 18 Oct 2024 14:55:47 +0000 (UTC) X-FDA: 82687023090.16.BA6F3F2 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by imf03.hostedemail.com (Postfix) with ESMTP id 052742000C for ; Fri, 18 Oct 2024 14:56:02 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of roberto.sassu@huaweicloud.com designates 14.137.139.154 as permitted sender) smtp.mailfrom=roberto.sassu@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729263261; a=rsa-sha256; cv=none; b=vCDJke/rpBh57rApkDpTGuQ3xza5P5rDXddhwEB9q4yoTIhyJRxTi1CgtgB7X+WHBV1Zy+ WjabqQr+Qipuc8SYyCv+NBU6AOEwGbZiWuZsLH3zrpg+hR5W1/eNWbejyQTZiE4oNQKENM JvG+YMS0Cg1L6sBIYgT/eSjslb0yJ4Q= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of roberto.sassu@huaweicloud.com designates 14.137.139.154 as permitted sender) smtp.mailfrom=roberto.sassu@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729263261; h=from:from:sender: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=MNIfnoJ4S3F903vJf38sGm2l/H7//YXIaz2t4r8wyd8=; b=vQCaM9aq2HLdhFSGLSQV2ZEx/iogSeaBoOFgSv5N8yPNBftC0Mh62EpWCCmqt+RWQnCeqF uwIMV80sXLCu7u3yyrbGTYbePWNnZ06YdFI1d2t+Y38m//cxJT3IzA6yo4l6P+5FzckCpf NZbWn24BjP89SpqCq+1acQKAAHyNlNs= Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4XVRtP0kP5z9v7JP for ; Fri, 18 Oct 2024 22:29:49 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id EBF6314039E for ; Fri, 18 Oct 2024 22:55:59 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwCHNsf1dhJnRHggAw--.63843S2; Fri, 18 Oct 2024 15:55:59 +0100 (CET) Message-ID: <46d8cfe7db6f381c99455159bff1c2220dff4aed.camel@huaweicloud.com> Subject: Re: [syzbot] [integrity?] [lsm?] possible deadlock in process_measurement (4) From: Roberto Sassu To: Paul Moore Cc: Shu Han , syzbot , akpm@linux-foundation.org, dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com, hughd@google.com, jmorris@namei.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, roberto.sassu@huawei.com, serge@hallyn.com, stephen.smalley.work@gmail.com, syzkaller-bugs@googlegroups.com, zohar@linux.ibm.com Date: Fri, 18 Oct 2024 16:55:47 +0200 In-Reply-To: <1a1d106ea8bba8abc1d3f3cd6fdd71d03edcf764.camel@huaweicloud.com> References: <66f7b10e.050a0220.46d20.0036.GAE@google.com> <05e893036fa8753e0177db99dd48eb9d2e33476a.camel@huaweicloud.com> <70f55efdba0e682907c895ea8ba537ea435bc3aa.camel@huaweicloud.com> <1a1d106ea8bba8abc1d3f3cd6fdd71d03edcf764.camel@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID:GxC2BwCHNsf1dhJnRHggAw--.63843S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWrWDGF1UGr43XrWxJr15twb_yoWrXFWkpF 93Wa4Ikr4DtFyUArn2yr1UW3Wjy34UGryUWr95Jr18JFyqvF1ktr17Jr1ruryUGr95C342 qr4UWryfJw1DArDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvYb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxkF7I0En4kS 14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I 8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWr XwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x 0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_ Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 j7l19UUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAABGcRxH8K8AABsw X-Rspamd-Queue-Id: 052742000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 9yooe1g4dzhgmohxygm1xzgefhyutk44 X-HE-Tag: 1729263362-55776 X-HE-Meta: U2FsdGVkX19nrpVVaDqGVhd8IWrW+2k79ySGup25a7/DmqSa+Upg74BfPRqbhnnJ0JielUOvWYo2CbY0u7Ee5um85axd2Wkw2OT6buLnZka2qIiwttEXLjuZ5tyoMCGCAelLOY7eSuL5syyNbXmBYVaSSH0sDMz5nGf0pA3rd+EaSvaGlHe5Y6Y9Kytc4gmZ8uXkK2HCeVmgCwz31nt9bJ1AaSihwJOz4C+8uXVqniXMLHCL+VHgJwoJonv3AZfv8/5/RPzSU6Db0AIslktYZizLCVZ+URYmb3xf8R0L3IgVvlMBLyAkp3H/mK4Od6yDYJnPckU6xwdE8VerLMUMAPnFdt2itxbKAOnBc9mXJWBXdKEN26wkI5g2zKw7R7HsHM/kn3tEzRMUnmYpSjQojb7DiyoIVF3pI0bFGNyvH/Lf1iK23Tc41KWyxH9JJ1csZrw5K9DV6gUMob6uEPrcrxnOacEPruuPYyu+BwQ0Gq/6NYkQKD1oqc80O8nnPxQAKuSIq9qFUlw2Kio114k3uw9zZw+VAks8VO8hnE6lf3rrqI84YZx9SeJeHr+9iiaCaYucitZlSqdDux+wkBogLPUahk/oSQqgKyz00lKbLFcOk3+ZDOHo4XmJ60fnw7VcmHnPtMQOVR++OwDwyvCqYHr9DJ30GcCJcFrzdL8WJM7AiOwLKedW+TZgMEdOOQONgIClDSQqZU/XnEdwOX1/xuL/jQGBKEAkrQIzJ4to726v5mpvqLp5UrNJNg9nxiyiR0tnTzlGdBPlqBLJtmkP69QJawFuAQPvyuRWNQnX2GT4x56ECOsnpdiUwLiKV8Q8dDa5gCBlebfZbXUc/2PoBR57MsfnpXDFgGi+14OniPuqUU/Zxqy0sP33pp01fxDYyFwQTnt/6H99k7b8i9vE/e9rhHaE88Qi3+6hMb1MaUyVLELo0K6B9/RUccfwW8SkUU4I+YQMrOgH2dmW3Vo Q5xU5i4x 6oX3eS5s/9eTBMWKqAK6BNfc+Fm1otJcEvfKM+7RVIVVKdVHlSBeslZLpXxHTotxKsuXwAtSo244IRtyr9xxXzq48WY77wZcY2W7ofFnmPrBaHpEjx4F37eUPVoAMS55VRv+KtjAkfjwCGWpVySa3gk6LzTNtgA4maIui3HONCsKwKtyjfckJ9arYX6oIMzcb1230woDD1S8V7BqkHYB1ztw0zI14948uc7oTyRXNLiVhB9t1W+FfhDJqitThy2ZJk8klH83+0NNcJQ2LbUMxHGHqhvOlGvqrYIwDjx6UPMwFcFeoCqFyqQ4kmWVIbUPqcafTwslXBllVkWEzU3WUxwPLnEODa/g5WjnyxUdNRnHpAIFKsT3DTJV79fQIDPpOnei2 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: On Wed, 2024-10-09 at 18:23 +0200, Roberto Sassu wrote: > On Mon, 2024-10-07 at 12:58 -0400, Paul Moore wrote: > > On Mon, Oct 7, 2024 at 12:49=E2=80=AFPM Roberto Sassu > > wrote: > > > On Mon, 2024-10-07 at 12:35 -0400, Paul Moore wrote: > > > > On Mon, Oct 7, 2024 at 11:31=E2=80=AFAM Roberto Sassu > > > > wrote: > > > > > On Wed, 2024-10-02 at 23:09 -0400, Paul Moore wrote: > > > > > > On Sat, Sep 28, 2024 at 2:08=E2=80=AFPM Shu Han wrote: > > > > > > >=20 > > > > > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > > > > > WARNING: possible circular locking dependency detected > > > > > > > > 6.11.0-syzkaller-10045-g97d8894b6f4c #0 Not tainted > > > > > > > > ------------------------------------------------------ > > > > > > > > syz-executor369/5231 is trying to acquire lock: > > > > > > > > ffff888072852370 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3},= at: inode_lock include/linux/fs.h:815 [inline] > > > > > > > > ffff888072852370 (&sb->s_type->i_mutex_key#12){+.+.}-{3:3},= at: process_measurement+0x439/0x1fb0 security/integrity/ima/ima_main.c:250 > > > > > > > >=20 > > > > > > > > but task is already holding lock: > > > > > > > > ffff88807ac9a798 (&mm->mmap_lock){++++}-{3:3}, at: mmap_wri= te_lock_killable include/linux/mmap_lock.h:122 [inline] > > > > > > > > ffff88807ac9a798 (&mm->mmap_lock){++++}-{3:3}, at: __do_sys= _remap_file_pages mm/mmap.c:1649 [inline] > > > > > > > > ffff88807ac9a798 (&mm->mmap_lock){++++}-{3:3}, at: __se_sys= _remap_file_pages+0x22d/0xa50 mm/mmap.c:1624 > > > > > > > >=20 > > > > > > > > which lock already depends on the new lock. > > > > > > >=20 > > > > > > > This issue (if not a false positive?) is due to the possible = `prot` > > > > > > > change caused by the processing logic for READ_IMPLIES_EXEC i= n do_mmap(), > > > > > > > so the remap_file_pages() must perform LSM check before calli= ng do_mmap(), > > > > > > > this is what the previous commit want to do. > > > > > >=20 > > > > > > My apologies for the delay on this, I was traveling for a bit a= nd > > > > > > missed this issue while away. > > > > > >=20 > > > > > > Looking quickly at the report, I don't believe this is a false = positive. > > > > > >=20 > > > > > > > The LSM check is required to know what the `prot` is, but `pr= ot` must be > > > > > > > obtained after holding the `mmap_write_lock`. > > > > > > >=20 > > > > > > > If the `mmap_write_lock` is released after getting the `prot`= and before > > > > > > > the LSM call in remap_file_pages(), it may cause TOCTOU. > > > > > >=20 > > > > > > Looking at the IMA code, specifically the process_measurement() > > > > > > function which is called from the security_mmap_file() LSM hook= , I'm > > > > > > not sure why there is the inode_lock() protected region. Mimi? > > > > > > Roberto? My best guess is that locking the inode may have been > > > > > > necessary before we moved the IMA inode state into the inode's = LSM > > > > > > security blob, but I'm not certain. > > > > > >=20 > > > > > > Mimi and Roberto, can we safely remove the inode locking in > > > > > > process_measurement()? > > > > >=20 > > > > > I discussed a bit with Mimi. Her concern was the duplicate iint > > > > > structure creation during concurrent file accesses. Now that inod= e > > > > > integrity metadata have been moved to the inode security blob, we= can > > > > > take the iint->mutex out of the ima_iint_cache structure, and sto= re it > > > > > directly in the security blob. In this way, we can remove the ino= de > > > > > lock. > > > > >=20 > > > > > Will write a patch and see if it passes our tests. > > > >=20 > > > > That's great, thanks Roberto. Assuming all goes well we'll want to > > > > backport this everywhere we merged the remap_file_pages() patch. > > >=20 > > > Welcome. Probably it can go down only until the kernel where IMA and > > > EVM are LSMs. > >=20 > > Yes, we'll need to look at that once we solve this in Linus' tree. >=20 > #syz test: https://github.com/robertosassu/linux.git ima-remove-inode-loc= k-v1 #syz test: https://github.com/robertosassu/linux.git remap-file-pages-locki= ng-v1