Landlock: LANDLOCK_ACCESS_FS_IOCTL_DEV bypass via io_uring IORING_OP_URING_CMD
Subsystems (4)
Hello Mickaël, and Landlock / io_uring folks,
A task confined by a Landlock ruleset that grants READ_FILE/WRITE_FILE on a block or NVMe character device but withholds LANDLOCK_ACCESS_FS_IOCTL_DEV can still reach the device-command surface through io_uring IORING_OP_URING_CMD with the IOCTL_DEV check bypassed: the request enters the device-command handler (block discard, or the NVMe char-device passthrough) where the equivalent ioctl(2) is denied. The destructive completion and the NVMe-admin surface follow from the code -- see Impact.
Affected
--------
Any kernel with CONFIG_SECURITY_LANDLOCK=y and Landlock enabled that supports LANDLOCK_ACCESS_FS_IOCTL_DEV (Landlock ABI >= 5, since Linux 6.8) and io_uring uring_cmd for the device class (block BLOCK_URING_CMD_DISCARD; NVMe passthrough). Confirmed by source inspection on mainline (v7.1-rc7) and reproduced on Linux 7.0.11 (Landlock ABI 8). The confined task needs a writable fd to a device it is legitimately allowed to use (e.g. a partition/loop device or an NVMe namespace passed into a container or granted by the ruleset); no CAP is required to reach the io_uring path. The gap is structural -- Landlock has never registered a uring_cmd hook -- so it is present from ABI 5 (Linux 6.8) through current mainline (v7.1-rc7) and is not a regression tied to a single Fixes: commit.
Root cause
----------
On the ioctl(2) path, the syscall handler in fs/ioctl.c calls security_file_ioctl() (its only call site on the ioctl(2) path) before dispatching to do_vfs_ioctl(); that reaches Landlock hook_file_ioctl_common(), which denies a device ioctl unless the file'sallowed_access holds LANDLOCK_ACCESS_FS_IOCTL_DEV (BLKDISCARD/BLKSECDISCARD/ BLKZEROOUT and NVMe passthrough are not in the is_masked_device_ioctl() allow-list, so they require the right).
io_uring reaches the same device-command surface by a different producer:
IORING_OP_URING_CMD -> io_uring_cmd() io_uring/uring_cmd.c -> security_uring_cmd(ioucmd) (the ONLY LSM gate on this path) -> file->f_op->uring_cmd() e.g. blkdev_uring_cmd() / nvme_ns_chr_uring_cmd()
Landlock's LSM_HOOK_INIT list (security/landlock/fs.c, net.c, task.c) registers file_ioctl/file_ioctl_compat but no uring_cmd hook -- only SELinux (selinux_uring_cmd) and Smack (smack_uring_cmd) gate this surface -- so security_uring_cmd() returns 0 for a Landlocked task and hook_file_ioctl / IOCTL_DEV is never consulted. For block, blkdev_cmd_discard() is then gated only by BLK_OPEN_WRITE; for NVMe, nvme_ns_chr_uring_cmd() reaches the admin/IO passthrough with no security_file_ioctl on the path. There is no shared helper that re-applies the IOCTL_DEV check.
SELinux and Smack hooking uring_cmd while Landlock does not is the coverage asymmetry; the Landlock documentation describes IOCTL_DEV as gating ioctl(2) but does not mention io_uring.
Reproducer
----------
A self-contained PoC is available on request (it needs root only to set up a loop block device and open it; Landlock enforcement is uid-independent, so the confined child demonstrates the gap regardless of the setup uid). The child applies a Landlock ruleset handling READ_FILE|WRITE_FILE|IOCTL_DEV with a rule granting only READ_FILE|WRITE_FILE on the device, then:
(1) ioctl(fd, BLKDISCARD, range) -> -EACCES (Landlock enforces IOCTL_DEV)
(2) IORING_OP_URING_CMD,
cmd_op = BLOCK_URING_CMD_DISCARD -> reaches the block command handler
Observed on Linux 7.0.11 (Landlock ABI 8):
[1] ioctl(BLKDISCARD) -> ret=-1 errno=13 (Permission denied)
[2] uring_cmd(DISCARD) -> cqe.res=-22 (Invalid argument)
A Landlock denial is always -EACCES; the io_uring path returned -EINVAL, which originates in a post-authorization check inside the block command handler (blk_validate_byte_range() in blkdev_cmd_discard()), reached only after security_uring_cmd() returned 0. So this run demonstrates the authorization bypass -- the request traversed the LSM gate into the block device-command handler with no IOCTL_DEV check -- and then failed a parameter check, not an authorization check. The destructive completion (an authorized discard with a granularity-aligned range) is the expected behaviour but was not exercised in this run.
Impact
------
Demonstrated: the LANDLOCK_ACCESS_FS_IOCTL_DEV authorization is bypassed. The device-command request reaches the block command handler with no Landlock check; the only remaining gate is BLK_OPEN_WRITE (held, since the policy granted write). Inferred from the code, not exercised here: an authorized DISCARD with a valid range completes (DISCARD/secure-erase semantics, destroying on-device data), and the same missing hook leaves the NVMe char-device uring_cmd surface ungated -- nvme_ns_chr_uring_cmd (namespace device /dev/nvmeXnY) -> nvme_ns_uring_cmd for NVME_URING_CMD_IO/IO_VEC passthrough, and nvme_dev_uring_cmd (controller device /dev/nvmeX) for NVME_URING_CMD_ADMIN (format, sanitize, firmware download, security send) -- both reach f_op->uring_cmd with no Landlock/IOCTL_DEV gate.
So the confirmed finding is a missing authorization (the confined task escapes its own IOCTL_DEV restriction); the destructive data effect and the NVMe-admin high-water-mark follow from the code but are not shown in the run above. The proven authorization bypass alone scores CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:H/A:N (6.5 Medium) -- S:C because the confined task crosses the Landlock policy boundary it was placed under, I:H because the bypassed path reaches a handler whose authorized completion modifies device data. With the device command completing destructively the projected ceiling is CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:H/A:H (8.4 High), the A:H component reasoned from the source rather than executed. No memory safety is involved.
Suggested direction
-------------------
Have Landlock register a uring_cmd hook that maps the device command to the same checks the ioctl path applies (IOCTL_DEV, and truncate where relevant), so a single chokepoint covers every f_op->uring_cmd provider (block, NVMe, ublk, and any future one). Mirrors how SELinux/Smack already gate this surface.
I am happy to send a patch for this if you would like.
Best regards,
Bryam Vargas
Independent security researcher, HEXLAB S.A.S., Cali, Colombia [email protected]
Jens Axboe
maintainerQuoted 10 lines · Bryam Vargas
Hello Micka?l, and Landlock /
io_uringfolks,A task confined by a Landlock ruleset that grants READ_FILE/WRITE_FILE on a block or NVMe character device but withholds
LANDLOCK_ACCESS_FS_IOCTL_DEVcan still reach the device-command surface throughio_uringIORING_OP_URING_CMDwith theIOCTL_DEVcheck
bypassed: the request enters the device-command handler (block discard, or the NVMe char-device passthrough) where the equivalent ioctl(2) is denied. The destructive completion and the NVMe-admin surface follow from the code -- see Impact.
I've said this before, but apparently it hasn't been received - this isn't an io_uring issue. If landlock is missing a hook, then that's on landlock and they should add it. Other security handlers already have that. Hence no need to broadcast this to a bunch of lists, it's strictly a landlock issue.
Signature · 1 line
Jens Axboe
Thanks Jens — noted, the fix belongs in Landlock. Mickaël has the full report.
Bryam
Jens Axboe
maintainerQuoted 2 lines · Bryam Vargas
Thanks Jens ? noted, the fix belongs in Landlock. Micka?l has the full report.
Indeed - and hence no need to bother anyone else with it by blasting it wide. I've already explained this multiple times, but on the private security list, when the occasional AI report comes in on things like this. Hence why it's a bit tiring to see the same stuff come across, once again.
For the landlock folks, I'd suggest taking a look at what hooks already exists (and existed, when landlock was merged) for selinux etc, that'd be a really good hint on the existing surface covered.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 2 lines · Bryam Vargas
Thanks Jens ? noted, the fix belongs in Landlock. Micka?l has the full report.
Indeed - and hence no need to bother anyone else with it by blasting it wide. I've already explained this multiple times, but on the private security list, when the occasional AI report comes in on things like this. Hence why it's a bit tiring to see the same stuff come across, once again.
Quoted 3 lines
For the landlock folks, I'd suggest taking a look at what hooks already exists (and existed, when landlock was merged) for selinux etc, that'd be a really good hint on the existing surface covered.
As I explained in previous (private) reports, there is currently no io_uring hooks implemented for Landlock because there is no use for them.
io_uring "bypass" was already mentioned to us two times in March but io_uring personality credential is not a Landlock bypass. The Landlock threat model is about enforcing restrictions when accessing new kernel resources, on a sandboxed subject. The credential identifies a set of access rights, so in the case of io_uring, the subject is inherited by the io_uring personality (i.e. the file descriptor). If a sandboxed task creates an io_uring personality, it will be sandboxed with the same restrictions, which is BTW an interesting property (e.g. pass a restricted io_uring FD to processes)
A sandboxed process cannot create an io_uring personality that would bypass its own restrictions, so there is no Landlock bypass. Inheriting or receiving a file descriptor is not restricted by Landlock because these are operations from outside (or before) the sandbox. If we want to restrict them, we need to restrict the processes creating such file descriptor.
Inherited or passed file descriptors are outside the Landlock threat model because Landlock is only one part of the security policy when (willingly) interacting with other processes. In a nutshell, it's the security capability model (where an object has some associated rights). For instance, if a process willingly passes a file descriptor tied to a secret file, then the receiving side can (and should be able to) read it, being sandboxed with Landlock or not. The scope of Landlock is to drop ambient rights, but if an *unsandboxed* process is OK to pass a sensitive resource, then that's a security architecture issue (i.e. a confused deputy attack).
A nice side effect of this approach is that a process can sandbox itself with a specific Landlock security policy and create an io_uring file descriptor that will inherit the Landlock restrictions. It can then pass this FD to other processes with the guarantee that this FD will only give access to resources allowed by the Landlock policy.
Landlock could implement the security_uring_sqpoll() hook, but for now the use case is not clear to me. We are working on controling socket creation according to they properties and I think the same approach would be useful for IO_URING:
https://lore.kernel.org/r/[email protected]
I agree that this might be confusing and I plan to improve Landlock documentation to make this clear and simpler for AI to take into account.
BTW, we also have an opened issue to add io_uring tests:
https://github.com/landlock-lsm/linux/issues/23
Regards,
Mickaël
Jens Axboe
maintainerQuoted 59 lines · Micka?l Sala?n
Quoted 10 lines · Jens Axboe
Quoted 2 lines · Bryam Vargas
Thanks Jens ? noted, the fix belongs in Landlock. Micka?l has the full report.
Indeed - and hence no need to bother anyone else with it by blasting it wide. I've already explained this multiple times, but on the private security list, when the occasional AI report comes in on things like this. Hence why it's a bit tiring to see the same stuff come across, once again.
Quoted 3 lines
For the landlock folks, I'd suggest taking a look at what hooks already exists (and existed, when landlock was merged) for selinux etc, that'd be a really good hint on the existing surface covered.
As I explained in previous (private) reports, there is currently no
io_uringhooks implemented for Landlock because there is no use for them.
io_uring"bypass" was already mentioned to us two times in March butio_uringpersonality credential is not a Landlock bypass. The Landlock threat model is about enforcing restrictions when accessing new kernel resources, on a sandboxed subject. The credential identifies a set of access rights, so in the case ofio_uring, the subject is inherited by theio_uringpersonality (i.e. the file descriptor). If a sandboxed task creates anio_uringpersonality, it will be sandboxed with the same restrictions, which is BTW an interesting property (e.g. pass a restrictedio_uringFD to processes)A sandboxed process cannot create an
io_uringpersonality that would bypass its own restrictions, so there is no Landlock bypass. Inheriting or receiving a file descriptor is not restricted by Landlock because these are operations from outside (or before) the sandbox. If we want to restrict them, we need to restrict the processes creating such file descriptor.Inherited or passed file descriptors are outside the Landlock threat model because Landlock is only one part of the security policy when (willingly) interacting with other processes. In a nutshell, it's the security capability model (where an object has some associated rights). For instance, if a process willingly passes a file descriptor tied to a secret file, then the receiving side can (and should be able to) read it, being sandboxed with Landlock or not. The scope of Landlock is to drop ambient rights, but if an *unsandboxed* process is OK to pass a sensitive resource, then that's a security architecture issue (i.e. a confused deputy attack).
A nice side effect of this approach is that a process can sandbox itself with a specific Landlock security policy and create an
io_uringfile descriptor that will inherit the Landlock restrictions. It can then pass this FD to other processes with the guarantee that this FD will only give access to resources allowed by the Landlock policy.Landlock could implement the
security_uring_sqpoll()hook, but for now the use case is not clear to me. We are working on controling socket creation according to they properties and I think the same approach would be useful forIO_URING:
https://lore.kernel.org/r/[email protected]
Quoted 3 lines
I agree that this might be confusing and I plan to improve Landlock documentation to make this clear and simpler for AI to take into account.
I think updating the documentation is a good idea. Most of these are AI nonsense anyway, and it'd hopefully help if the documentation reflected what you wrote above. Even if not, then at least when the next one of these slop reports come in, the reply can be as simple as just linking to the documentation.
Quoted 2 lines
BTW, we also have an opened issue to add
io_uringtests:
https://github.com/landlock-lsm/linux/issues/23
Nice!
Signature · 1 line
Jens Axboe
Quoted 4 lines · Mickaël Salaün
As I explained in previous (private) reports, there is currently no
io_uringhooks implemented for Landlock because there is no use for them.
Quoted 9 lines
io_uring"bypass" was already mentioned to us two times in March butio_uringpersonality credential is not a Landlock bypass. The Landlock threat model is about enforcing restrictions when accessing new kernel resources, on a sandboxed subject. The credential identifies a set of access rights, so in the case ofio_uring, the subject is inherited by theio_uringpersonality (i.e. the file descriptor). If a sandboxed task creates anio_uringpersonality, it will be sandboxed with the same restrictions, which is BTW an interesting property (e.g. pass a restrictedio_uringFD to processes)
Remark on the side: We have previously received bug reports due to io_uring using different credentials, but this report is not about that.
Instead, it is about the block device "discard" operation, which is accessible through both (a) the ioctl() interface and (b) an io_uring interface. The report is, in my reading, about the fact that the access through (a) can be blocked with Landlock, while the access through (b) can not be blocked through Landlock. (See the other answer I sent.)
But either way, as you are also saying here, we should probably document better what the threat model for Landlock is, so that security researchers (and AI models) can refer to that. It'll result in less work for everyone.
I opened https://github.com/landlock-lsm/linux/issues/64 to track it and collected some notes.
—Günther
Hello Bryam!
Thanks for the report!
Quoted 103 lines · Bryam Vargas
Hello Mickaël, and Landlock /
io_uringfolks,A task confined by a Landlock ruleset that grants READ_FILE/WRITE_FILE on a block or NVMe character device but withholds
LANDLOCK_ACCESS_FS_IOCTL_DEVcan still reach the device-command surface throughio_uringIORING_OP_URING_CMDwith theIOCTL_DEVcheck bypassed: the request enters the device-command handler (block discard, or the NVMe char-device passthrough) where the equivalent ioctl(2) is denied. The destructive completion and the NVMe-admin surface follow from the code -- see Impact.Affected
--------
Any kernel withCONFIG_SECURITY_LANDLOCK=yand Landlock enabled that supportsLANDLOCK_ACCESS_FS_IOCTL_DEV(Landlock ABI >= 5, since Linux 6.8) andio_uringuring_cmdfor the device class (blockBLOCK_URING_CMD_DISCARD; NVMe passthrough). Confirmed by source inspection on mainline (v7.1-rc7) and reproduced on Linux 7.0.11 (Landlock ABI 8). The confined task needs a writable fd to a device it is legitimately allowed to use (e.g. a partition/loop device or an NVMe namespace passed into a container or granted by the ruleset); no CAP is required to reach theio_uringpath. The gap is structural -- Landlock has never registered auring_cmdhook -- so it is present from ABI 5 (Linux 6.8) through current mainline (v7.1-rc7) and is not a regression tied to a single Fixes: commit.Root cause
----------
On the ioctl(2) path, the syscall handler infs/ioctl.ccallssecurity_file_ioctl()(its only call site on the ioctl(2) path) before dispatching todo_vfs_ioctl(); that reaches Landlockhook_file_ioctl_common(), which denies a device ioctl unless the file'sallowed_accessholdsLANDLOCK_ACCESS_FS_IOCTL_DEV(BLKDISCARD/BLKSECDISCARD/ BLKZEROOUT and NVMe passthrough are not in theis_masked_device_ioctl()allow-list, so they require the right).
io_uringreaches the same device-command surface by a different producer:IORING_OP_URING_CMD -> io_uring_cmd() io_uring/uring_cmd.c -> security_uring_cmd(ioucmd) (the ONLY LSM gate on this path) -> file->f_op->uring_cmd() e.g. blkdev_uring_cmd() / nvme_ns_chr_uring_cmd()Landlock's
LSM_HOOK_INITlist (security/landlock/fs.c,net.c,task.c) registers file_ioctl/file_ioctl_compat but nouring_cmdhook -- only SELinux (selinux_uring_cmd) and Smack (smack_uring_cmd) gate this surface -- sosecurity_uring_cmd()returns 0 for a Landlocked task andhook_file_ioctl/IOCTL_DEVis never consulted. For block,blkdev_cmd_discard()is then gated only byBLK_OPEN_WRITE; for NVMe,nvme_ns_chr_uring_cmd()reaches the admin/IO passthrough with nosecurity_file_ioctlon the path. There is no shared helper that re-applies theIOCTL_DEVcheck.SELinux and Smack hooking
uring_cmdwhile Landlock does not is the coverage asymmetry; the Landlock documentation describesIOCTL_DEVas gating ioctl(2) but does not mentionio_uring.Reproducer
----------
A self-contained PoC is available on request (it needs root only to set up a loop block device and open it; Landlock enforcement is uid-independent, so the confined child demonstrates the gap regardless of the setup uid). The child applies a Landlock ruleset handling READ_FILE|WRITE_FILE|IOCTL_DEV with a rule granting only READ_FILE|WRITE_FILE on the device, then:(1)
ioctl(fd, BLKDISCARD, range)->-EACCES(Landlock enforcesIOCTL_DEV)
(2)IORING_OP_URING_CMD,cmd_op = BLOCK_URING_CMD_DISCARD -> reaches the block command handlerObserved on Linux 7.0.11 (Landlock ABI 8):
[1] ioctl(BLKDISCARD) -> ret=-1 errno=13 (Permission denied)
[2]uring_cmd(DISCARD)-> cqe.res=-22 (Invalid argument)A Landlock denial is always
-EACCES; theio_uringpath returned-EINVAL, which originates in a post-authorization check inside the block command handler (blk_validate_byte_range()inblkdev_cmd_discard()), reached only aftersecurity_uring_cmd()returned 0. So this run demonstrates the authorization bypass -- the request traversed the LSM gate into the block device-command handler with noIOCTL_DEVcheck -- and then failed a parameter check, not an authorization check. The destructive completion (an authorized discard with a granularity-aligned range) is the expected behaviour but was not exercised in this run.Impact
------
Demonstrated: theLANDLOCK_ACCESS_FS_IOCTL_DEVauthorization is bypassed. The device-command request reaches the block command handler with no Landlock check; the only remaining gate isBLK_OPEN_WRITE(held, since the policy granted write). Inferred from the code, not exercised here: an authorized DISCARD with a valid range completes (DISCARD/secure-erase semantics, destroying on-device data), and the same missing hook leaves the NVMe char-deviceuring_cmdsurface ungated --nvme_ns_chr_uring_cmd(namespace device/dev/nvmeXnY) ->nvme_ns_uring_cmdfor NVME_URING_CMD_IO/IO_VEC passthrough, andnvme_dev_uring_cmd(controller device/dev/nvmeX) forNVME_URING_CMD_ADMIN(format, sanitize, firmware download, security send) -- both reachf_op->uring_cmdwith no Landlock/IOCTL_DEV gate.So the confirmed finding is a missing authorization (the confined task escapes its own
IOCTL_DEVrestriction); the destructive data effect and the NVMe-admin high-water-mark follow from the code but are not shown in the run above. The proven authorization bypass alone scores CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:H/A:N (6.5 Medium) -- S:C because the confined task crosses the Landlock policy boundary it was placed under, I:H because the bypassed path reaches a handler whose authorized completion modifies device data. With the device command completing destructively the projected ceiling is CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:H/A:H (8.4 High), the A:H component reasoned from the source rather than executed. No memory safety is involved.
Quoted 8 lines
Suggested direction
-------------------
Have Landlock register auring_cmdhook that maps the device command to the same checks the ioctl path applies (IOCTL_DEV, and truncate where relevant), so a single chokepoint covers everyf_op->uring_cmdprovider (block, NVMe, ublk, and any future one). Mirrors how SELinux/Smack already gate this surface.I am happy to send a patch for this if you would like.
I have read through the code a bit, but I am not sure I follow the argument of this report. Let me paraphrase my understanding --
* LANDLOCK_ACCESS_FS_IOCTL_DEV is documented as blocking ioctl(2) commands on opened character and block devices.
(c.f. https://docs.kernel.org/userspace-api/landlock.html#filesystem-flags)
* One of many block-device IOCTL operations is BLKDISCARD.
* Block devices offer BLKDISCARD over io_uring as well,
but io_uring does *not* offer a generic interface through which you can do IOCTLs. It *only* implements BLOCK_URING_CMD_DISCARD in that place. The header where that constant is defined happens to use one of the ioctl macros to construct the number, but points out that "It's a different number space from ioctl()" (see include/uapi/linux/blkdev.h).
So... while this is similar to IOCTL, and while this block device operation is also available through ioctl(2), this is a different command multiplexer than IOCTL and I am not convinced that that namespace should be guarded with the same LANDLOCK_ACCESS_FS_IOCTL_DEV access right.
Do I understand correctly that the only operation affected in this report is BLOCK_URING_CMD_DISCARD? Or are there other operations affected by this (through other devices)? I saw you also mentioned the truncate right above, but I assume that for this access right you have not found a way to side-step it (assuming that this calls the more specific LSM hooks).
Thanks,
—Günther
Thanks Günther, and thanks for filing #64.
Straight to your two questions:
1. Block: you're right. blkdev_uring_cmd() has a single case, BLOCK_URING_CMD_DISCARD, and the blkdev.h note that it's a separate number space is fair, so I'm not arguing it should be a generic ioctl multiplexer. The "others, through other devices" are on
NVMe: the namespace char dev takes NVME_URING_CMD_IO / _IO_VEC, and AFAICT a write-capable confined task can reach IO passthrough (write, DSM/discard) with no capability, since nvme_cmd_allowed() only wants FMODE_WRITE there.
Correction to my own report: I overstated the ceiling. The NVMe admin ops (format, sanitize, firmware, security-send) sit behind capable(CAP_SYS_ADMIN) in nvme_cmd_allowed(), so a Landlocked unprivileged task can't reach them. The A:H / 8.4 figure was wrong; only namespace IO is in scope for a confined task.
2. Truncate: correct, no sidestep, and none looks possible. I went through every f_op->uring_cmd provider (block, NVMe, btrfs encoded I/O, FUSE, ublk, sockets, ...) and none change file size; truncate(2)/ftruncate(2) keep their own hook. Please ignore the "and truncate where relevant" line in my suggested direction, it was speculative.
On framing: I'm happy to call this a coverage gap rather than a bypass. IOCTL_DEV was never documented to cover io_uring, so nothing it promised is broken. The one hard fact is the asymmetry: ioctl(2) BLKDISCARD is denied (IOCTL_DEV, and it's not in is_masked_device_ioctl()), the same op via uring_cmd isn't, and SELinux/Smack already hook security_uring_cmd while Landlock doesn't. Whether that's worth a hook or just the doc clarification Mickaël mentioned is your call.
If you do want one, I can send an RFC for an all-or-nothing "IOCTL_DEV for any uring_cmd on a device file" hook (cmd_op is a private number space, so porting is_masked_device_ioctl() wouldn't be right). Otherwise I'll drop the provider detail into #64 and leave it at the doc fix.
Bryam
Hello Bryam!
Quoted 22 lines · Bryam Vargas
Thanks Günther, and thanks for filing #64.
Straight to your two questions:
1. Block: you're right.
blkdev_uring_cmd()has a single case,BLOCK_URING_CMD_DISCARD, and theblkdev.hnote that it's a separate number space is fair, so I'm not arguing it should be a generic ioctl multiplexer. The "others, through other devices" are on
NVMe: the namespace char dev takesNVME_URING_CMD_IO/_IO_VEC, and AFAICT a write-capable confined task can reach IO passthrough (write, DSM/discard) with no capability, sincenvme_cmd_allowed()only wantsFMODE_WRITEthere.Correction to my own report: I overstated the ceiling. The NVMe admin ops (format, sanitize, firmware, security-send) sit behind
capable(CAP_SYS_ADMIN)innvme_cmd_allowed(), so a Landlocked unprivileged task can't reach them. The A:H / 8.4 figure was wrong; only namespace IO is in scope for a confined task.2. Truncate: correct, no sidestep, and none looks possible. I went through every
f_op->uring_cmdprovider (block, NVMe, btrfs encoded I/O, FUSE, ublk, sockets, ...) and none change file size; truncate(2)/ftruncate(2) keep their own hook. Please ignore the "and truncate where relevant" line in my suggested direction, it was speculative.
Quoted 6 lines
On framing: I'm happy to call this a coverage gap rather than a bypass.
IOCTL_DEVwas never documented to coverio_uring, so nothing it promised is broken. The one hard fact is the asymmetry: ioctl(2) BLKDISCARD is denied (IOCTL_DEV, and it's not inis_masked_device_ioctl()), the same op viauring_cmdisn't, and SELinux/Smack already hooksecurity_uring_cmdwhile Landlock doesn't. Whether that's worth a hook or just the doc clarification Mickaël mentioned is your call.
Agreed, a coverage gap is in my mind the right way to think about it.
I filed this issue about that gap:
https://github.com/landlock-lsm/linux/issues/65
Even though that's technically a feature request, you are quite right pointing it out.
As I'm saying on that issue description as well, there are in principle multiple ways of blocking such a feature. It is possible to block it at the fine-grained layer in uring_cmd, but maybe a more practical way to go about it would be to block the creation of an io_uring itself, since most sandboxed processes do not normally make use of that feature.
(IMHO, we have already made a similar mistake in networking, where we first built restrictions for individual TCP operations, but left all the other protocols unrestricted. Maybe the better approach is to start with the coarser restriction that addresses the majority of use cases and then provide more granular controls later.)
I'd be interested to hear people's opinions.
(Mickaël, if you feel this is the wrong approach to frame this as feature request, also please speak up.)
Quoted 4 lines
If you do want one, I can send an RFC for an all-or-nothing "
IOCTL_DEVfor anyuring_cmdon a device file" hook (cmd_opis a private number space, so portingis_masked_device_ioctl()wouldn't be right). Otherwise I'll drop the provider detail into #64 and leave it at the doc fix.
I'd be happy to review your patches for the issue. But let's find a consensus on the overall approach first -- that will hopefully also save you from going to much in circles in the implementation.
Thanks!
—Günther
Günther,
Thanks, and #65 looks right.
On the approach: it's a Landlock-only change either way, both hooks already exist, so no io_uring core churn.
Coarse (block ring creation) can hang off security_uring_allowed(), the existing io_uring_setup() gate. That matches the creation-control direction Mickaël raised -- the socket-creation work he said would suit io_uring too -- and it's a fine default, since most sandboxes don't need io_uring. One caveat: it overlaps kernel.io_uring_disabled and a seccomp filter on io_uring_setup, so the Landlock-specific win is mainly composing it in a ruleset.
Fine-grained (gate device uring_cmd) is the only one that closes the asymmetry I reported. It uses security_uring_cmd() -- the hook SELinux and Smack already have and we don't -- and needs no new right: gate device files on the existing IOCTL_DEV, mirroring hook_file_ioctl_common(). All-or-nothing per device, since cmd_op is a private number space.
So I'd go coarse-first as you suggest, and keep the uring_cmd gate as the granular step; it's little code and reuses an existing right. Happy to prototype either once you and Mickaël settle on the shape; I'll hold until then.
Bryam