dma-buf: set SB_I_NOEXEC on the pseudo filesystem
Subsystems (3)
PATCH 1/1 dma-buf: set SB_I_NOEXEC on the pseudo filesystem
The dma-buf pseudo filesystem dispenses S_ANON_INODE inodes via alloc_anon_inode() but never sets SB_I_NOEXEC on its superblock. Since commit 1e7ab6f67824 ("anon_inode: rework assertions") in 6.17, path_noexec() warns on exactly that combination, so an mmap() on any dma-buf fd trips the warning:
WARNING: CPU: 11 PID: 121813 at fs/exec.c:118 path_noexec+0x47/0x50 do_mmap+0x2b5/0x680 vm_mmap_pgoff+0x129/0x210 ksys_mmap_pgoff+0x177/0x240 __x64_sys_mmap+0x33/0x70
dma-bufs have no business being executable, which is the invariant that the new assertion is enforcing. Set SB_I_NOEXEC on the dmabuf superblock.
Reproducer on a CONFIG_DEBUG_VFS=y kernel:
make -C tools/testing/selftests/dmabuf-heaps
sudo ./tools/testing/selftests/dmabuf-heaps/dmabuf-heap -t system
The selftest allocates from /dev/dma_heap/system and mmaps the returned fd, which trips the warning without this patch.
--- drivers/dma-buf/dma-buf.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma-buf/dma-buf.c +1 -0
@@ -216,6 +216,7 @@ static int dma_buf_fs_init_context(struct fs_context *fc)if (!ctx)return -ENOMEM ; ctx->dops = &dma_buf_dentry_ops; + fc->s_iflags |=SB_I_NOEXEC ;return 0 ; }
Signature · 1 line
2.54.0
Quoted 21 lines · John Hubbard
The dma-buf pseudo filesystem dispenses
S_ANON_INODEinodes viaalloc_anon_inode()but never setsSB_I_NOEXECon its superblock. Since commit1e7ab6f67824("anon_inode: rework assertions") in 6.17,path_noexec()warns on exactly that combination, so anmmap()on any dma-buf fd trips the warning:WARNING: CPU: 11 PID: 121813 at fs/exec.c:118 path_noexec+0x47/0x50 do_mmap+0x2b5/0x680 vm_mmap_pgoff+0x129/0x210 ksys_mmap_pgoff+0x177/0x240 __x64_sys_mmap+0x33/0x70dma-bufs have no business being executable, which is the invariant that the new assertion is enforcing. Set
SB_I_NOEXECon the dmabuf superblock.Reproducer on a
CONFIG_DEBUG_VFS=ykernel:make -C
tools/testing/selftests/dmabuf-heaps
sudo./tools/testing/selftests/dmabuf-heaps/dmabuf-heap-t system
Quoted 7 lines
The selftest allocates from
/dev/dma_heap/systemand mmaps the returned fd, which trips the warning without this patch.Fixes 1e7ab6f67824 ("anon_inode: rework assertions")Signed-off-by John Hubbard <[email protected]>---
Perfect, the asserts are paying off. Thanks!
drivers/dma-buf/dma-buf.c static int dma_buf_fs_init_context(struct fs_context *fc) · line 219
Quoted 12 lines
drivers/dma-buf/dma-buf.c | 1 + 1 file changed, 1 insertion(+)drivers/dma-buf/dma-buf.c +1
-0@@ -216,6 +216,7 @@ static int dma_buf_fs_init_context(struct fs_context *fc)if (!ctx)return -ENOMEM ; ctx->dops = &dma_buf_dentry_ops; + fc->s_iflags |=SB_I_NOEXEC ;
While you're at it, also raise SB_I_NODEV. You're not creating any device nodes and this is additional hardening.
Quoted 25 lines · Christian Brauner
Quoted 24 lines · John Hubbard
The dma-buf pseudo filesystem dispenses
S_ANON_INODEinodes viaalloc_anon_inode()but never setsSB_I_NOEXECon its superblock. Since commit1e7ab6f67824("anon_inode: rework assertions") in 6.17,path_noexec()warns on exactly that combination, so anmmap()on any dma-buf fd trips the warning:WARNING: CPU: 11 PID: 121813 at fs/exec.c:118 path_noexec+0x47/0x50 do_mmap+0x2b5/0x680 vm_mmap_pgoff+0x129/0x210 ksys_mmap_pgoff+0x177/0x240 __x64_sys_mmap+0x33/0x70dma-bufs have no business being executable, which is the invariant that the new assertion is enforcing. Set
SB_I_NOEXECon the dmabuf superblock.Reproducer on a
CONFIG_DEBUG_VFS=ykernel:make -C
tools/testing/selftests/dmabuf-heaps
sudo./tools/testing/selftests/dmabuf-heaps/dmabuf-heap-t systemThe selftest allocates from
/dev/dma_heap/systemand mmaps the returned fd, which trips the warning without this patch.
Quoted 7 lines
Quoted 4 lines
Fixes 1e7ab6f67824 ("anon_inode: rework assertions")Signed-off-by John Hubbard <[email protected]>---
Perfect, the asserts are paying off. Thanks!
Reviewed-by Christian Brauner (Amutable) <[email protected]>
Thanks for the review!
Quoted 4 lines
Quoted 4 lines
drivers/dma-buf/dma-buf.c | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
drivers/dma-buf/dma-buf.c static int dma_buf_fs_init_context(struct fs_context *fc) · line 219
Quoted 9 lines
drivers/dma-buf/dma-buf.c +1
-0@@ -216,6 +216,7 @@ static int dma_buf_fs_init_context(struct fs_context *fc)if (!ctx)return -ENOMEM ; ctx->dops = &dma_buf_dentry_ops; + fc->s_iflags |=SB_I_NOEXEC ;While you're at it, also raise
SB_I_NODEV. You're not creating any device nodes and this is additional hardening.
OK, I'll add that and send out a v2, after collecting any other feedback on this one.
thanks,
Signature · 1 line
John Hubbard