On Thu, Mar 07, 2024 at 01:21:48PM +0100, Arnd Bergmann wrote: > On Thu, Mar 7, 2024, at 13:15, Christian Brauner wrote: > > On Wed, Mar 06, 2024 at 04:18:53PM +0100, Arnd Bergmann wrote: > >> On Wed, Mar 6, 2024, at 14:47, Mickaël Salaün wrote: > >> > > >> > Arnd, Christian, Paul, are you OK with this new hook proposal? > >> > >> I think this sounds better. It would fit more closely into > >> the overall structure of the ioctl handlers with their multiple > >> levels, where below vfs_ioctl() calling into f_ops->unlocked_ioctl, > >> you have the same structure for sockets and blockdev, and > >> then additional levels below that and some weirdness for > >> things like tty, scsi or cdrom. > > > > So an additional security hook called from tty, scsi, or cdrom? > > And the original hook is left where it is right now? > > For the moment, I think adding another hook in vfs_ioctl() > and the corresponding compat path would do what Mickaël > wants. Beyond that, we could consider having hooks in > socket and block ioctls if needed as they are easy to > filter out based on inode->i_mode. > > The tty/scsi/cdrom hooks would be harder to do, let's assume > for now that we don't need them. Thank you all for the help! Yes, tty/scsi/cdrom are just examples. We do not need special features for these for Landlock right now. What I would do is to invoke the new LSM hook in the following two places in fs/ioctl.c: 1) at the top of vfs_ioctl() 2) at the top of ioctl_compat() (Both of these functions are just invoking the f_op->unlocked_ioctl() and f_op->compat_ioctl() operations with a safeguard for that being a NULL pointer.) The intent is that the new hook gets called everytime before an ioctl is sent to these IOCTL operations in f_op, so that the LSM can distinguish cleanly between the "safe" IOCTLs that are implemented fully within fs/ioctl.c and the "potentially unsafe" IOCTLs which are implemented by these hooks (as it is unrealistic for us to holistically reason about the safety of all possible implementations). The alternative approach where we try to do the same based on the existing LSM IOCTL hook resulted in the patch further up in this mail thread - it involves maintaining a list of "safe" IOCTL commands, and it is difficult to guarantee that these lists of IOCTL commands stay in sync. Christian, does that make sense in your mind? Thanks, —Günther