linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shu Han <ebpqwerty472123@gmail.com>
To: syzbot <syzbot+1cd571a672400ef3a930@syzkaller.appspotmail.com>
Cc: 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,
	 paul@paul-moore.com, roberto.sassu@huawei.com, serge@hallyn.com,
	 stephen.smalley.work@gmail.com, syzkaller-bugs@googlegroups.com,
	 zohar@linux.ibm.com
Subject: Re: [syzbot] [integrity?] [lsm?] possible deadlock in process_measurement (4)
Date: Sun, 29 Sep 2024 02:07:47 +0800	[thread overview]
Message-ID: <CAHQche-Gsy4=UT6+znKyPRDEHQm9y-MQ+zacoqfywKaz7VA2kg@mail.gmail.com> (raw)
In-Reply-To: <66f7b10e.050a0220.46d20.0036.GAE@google.com>

> ======================================================
> 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
>
> but task is already holding lock:
> ffff88807ac9a798 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_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
>
> which lock already depends on the new lock.

This issue (if not a false positive?) is due to the possible `prot`
change caused by the processing logic for READ_IMPLIES_EXEC in do_mmap(),
so the remap_file_pages() must perform LSM check before calling do_mmap(),
this is what the previous commit want to do.

The LSM check is required to know what the `prot` is, but `prot` must be
obtained after holding the `mmap_write_lock`.

If the `mmap_write_lock` is released after getting the `prot` and before
the LSM call in remap_file_pages(), it may cause TOCTOU.

So, possible solutions may include:
1. Remove the security check by removing the the possibility of the `prot`
   change:
1.1. move the the processing logic for READ_IMPLIES_EXEC out of the
     do_mmap(). This also ensures that such missing checks which the
     previous commit fixes will not occur again(suggested).
     See the RFC PATCH
     https://lore.kernel.org/all/20240928180044.50-1-ebpqwerty472123@gmail.com/
1.2. Replace do_mmap() in remap_file_pages() to mmap_region(), which do
     the actually memory mapping without the respect to READ_IMPLIES_EXEC.
     But this requires other checks in do_mmap() is performed in
     remap_file_pages(), such as the `file_mmap_ok`(may complex).
2. Perform operations similar to updating a value by CAS(may slow):
for (;;) {
    mmap_write_lock();
    prot = get_prot();
    mmap_write_unlock();
    if (!call_lsm(prot)) return;
    mmap_write_lock();
    if (prot != get_prot()) continue;
    do_mmap();
    mmap_write_unlock();
}


  parent reply	other threads:[~2024-09-28 18:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-28  7:32 syzbot
2024-09-28 13:56 ` Andrew Morton
2024-09-28 18:07 ` Shu Han [this message]
2024-10-03  3:09   ` Paul Moore
2024-10-03  7:35     ` Shu Han
2024-10-07 15:31     ` Roberto Sassu
2024-10-07 16:35       ` Paul Moore
2024-10-07 16:49         ` Roberto Sassu
2024-10-07 16:58           ` Paul Moore
2024-10-09 16:23             ` Roberto Sassu
2024-10-09 19:05               ` syzbot
2024-10-18 14:55               ` Roberto Sassu
2024-10-18 15:23                 ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHQche-Gsy4=UT6+znKyPRDEHQm9y-MQ+zacoqfywKaz7VA2kg@mail.gmail.com' \
    --to=ebpqwerty472123@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=hughd@google.com \
    --cc=jmorris@namei.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=stephen.smalley.work@gmail.com \
    --cc=syzbot+1cd571a672400ef3a930@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox