* [PATCH v1 1/2] landlock: Handle weird files
@ 2025-01-10 15:39 Mickaël Salaün
2025-01-10 15:39 ` [PATCH v1 2/2] landlock: Constify get_mode_access() Mickaël Salaün
2025-01-10 16:37 ` [PATCH v1 1/2] landlock: Handle weird files Günther Noack
0 siblings, 2 replies; 7+ messages in thread
From: Mickaël Salaün @ 2025-01-10 15:39 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, linux-fsdevel, linux-kernel,
linux-security-module, Paul Moore, Dave Chinner, Kent Overstreet,
syzbot+34b68f850391452207df, syzbot+360866a59e3c80510a62,
Ubisectech Sirius
A corrupted filesystem (e.g. bcachefs) might return weird files.
Instead of throwing a warning and allowing access to such file, treat
them as regular files.
Cc: Dave Chinner <david@fromorbit.com>
Cc: Günther Noack <gnoack@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Paul Moore <paul@paul-moore.com>
Reported-by: syzbot+34b68f850391452207df@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/000000000000a65b35061cffca61@google.com
Reported-by: syzbot+360866a59e3c80510a62@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/67379b3f.050a0220.85a0.0001.GAE@google.com
Reported-by: Ubisectech Sirius <bugreport@ubisectech.com>
Closes: https://lore.kernel.org/r/c426821d-8380-46c4-a494-7008bbd7dd13.bugreport@ubisectech.com
Fixes: cb2c7d1a1776 ("landlock: Support filesystem access-control")
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
security/landlock/fs.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/security/landlock/fs.c b/security/landlock/fs.c
index e31b97a9f175..7adb25150488 100644
--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -937,10 +937,6 @@ static access_mask_t get_mode_access(const umode_t mode)
switch (mode & S_IFMT) {
case S_IFLNK:
return LANDLOCK_ACCESS_FS_MAKE_SYM;
- case 0:
- /* A zero mode translates to S_IFREG. */
- case S_IFREG:
- return LANDLOCK_ACCESS_FS_MAKE_REG;
case S_IFDIR:
return LANDLOCK_ACCESS_FS_MAKE_DIR;
case S_IFCHR:
@@ -951,9 +947,12 @@ static access_mask_t get_mode_access(const umode_t mode)
return LANDLOCK_ACCESS_FS_MAKE_FIFO;
case S_IFSOCK:
return LANDLOCK_ACCESS_FS_MAKE_SOCK;
+ case S_IFREG:
+ case 0:
+ /* A zero mode translates to S_IFREG. */
default:
- WARN_ON_ONCE(1);
- return 0;
+ /* Treats weird files as regular files. */
+ return LANDLOCK_ACCESS_FS_MAKE_REG;
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] landlock: Constify get_mode_access()
2025-01-10 15:39 [PATCH v1 1/2] landlock: Handle weird files Mickaël Salaün
@ 2025-01-10 15:39 ` Mickaël Salaün
2025-01-10 16:39 ` Günther Noack
2025-01-10 16:37 ` [PATCH v1 1/2] landlock: Handle weird files Günther Noack
1 sibling, 1 reply; 7+ messages in thread
From: Mickaël Salaün @ 2025-01-10 15:39 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, linux-fsdevel, linux-kernel,
linux-security-module, Paul Moore
Use __attribute_const__ for get_mode_access().
Cc: Günther Noack <gnoack@google.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
security/landlock/fs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/landlock/fs.c b/security/landlock/fs.c
index 7adb25150488..f81d0335b825 100644
--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -932,7 +932,7 @@ static int current_check_access_path(const struct path *const path,
return check_access_path(dom, path, access_request);
}
-static access_mask_t get_mode_access(const umode_t mode)
+static __attribute_const__ access_mask_t get_mode_access(const umode_t mode)
{
switch (mode & S_IFMT) {
case S_IFLNK:
--
2.47.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] landlock: Handle weird files
2025-01-10 15:39 [PATCH v1 1/2] landlock: Handle weird files Mickaël Salaün
2025-01-10 15:39 ` [PATCH v1 2/2] landlock: Constify get_mode_access() Mickaël Salaün
@ 2025-01-10 16:37 ` Günther Noack
2025-01-11 15:38 ` Mickaël Salaün
1 sibling, 1 reply; 7+ messages in thread
From: Günther Noack @ 2025-01-10 16:37 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Günther Noack, linux-fsdevel, linux-kernel,
linux-security-module, Paul Moore, Dave Chinner, Kent Overstreet,
syzbot+34b68f850391452207df, syzbot+360866a59e3c80510a62,
Ubisectech Sirius
On Fri, Jan 10, 2025 at 04:39:13PM +0100, Mickaël Salaün wrote:
> A corrupted filesystem (e.g. bcachefs) might return weird files.
> Instead of throwing a warning and allowing access to such file, treat
> them as regular files.
>
> Cc: Dave Chinner <david@fromorbit.com>
> Cc: Günther Noack <gnoack@google.com>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> Cc: Paul Moore <paul@paul-moore.com>
> Reported-by: syzbot+34b68f850391452207df@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/r/000000000000a65b35061cffca61@google.com
> Reported-by: syzbot+360866a59e3c80510a62@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/r/67379b3f.050a0220.85a0.0001.GAE@google.com
> Reported-by: Ubisectech Sirius <bugreport@ubisectech.com>
> Closes: https://lore.kernel.org/r/c426821d-8380-46c4-a494-7008bbd7dd13.bugreport@ubisectech.com
> Fixes: cb2c7d1a1776 ("landlock: Support filesystem access-control")
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> ---
> security/landlock/fs.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/security/landlock/fs.c b/security/landlock/fs.c
> index e31b97a9f175..7adb25150488 100644
> --- a/security/landlock/fs.c
> +++ b/security/landlock/fs.c
> @@ -937,10 +937,6 @@ static access_mask_t get_mode_access(const umode_t mode)
> switch (mode & S_IFMT) {
> case S_IFLNK:
> return LANDLOCK_ACCESS_FS_MAKE_SYM;
> - case 0:
> - /* A zero mode translates to S_IFREG. */
> - case S_IFREG:
> - return LANDLOCK_ACCESS_FS_MAKE_REG;
> case S_IFDIR:
> return LANDLOCK_ACCESS_FS_MAKE_DIR;
> case S_IFCHR:
> @@ -951,9 +947,12 @@ static access_mask_t get_mode_access(const umode_t mode)
> return LANDLOCK_ACCESS_FS_MAKE_FIFO;
> case S_IFSOCK:
> return LANDLOCK_ACCESS_FS_MAKE_SOCK;
> + case S_IFREG:
> + case 0:
> + /* A zero mode translates to S_IFREG. */
> default:
> - WARN_ON_ONCE(1);
> - return 0;
> + /* Treats weird files as regular files. */
> + return LANDLOCK_ACCESS_FS_MAKE_REG;
> }
> }
>
> --
> 2.47.1
>
Reviewed-by: Günther Noack <gnoack3000@gmail.com>
Makes sense to me, since this is enforcing a stronger check than before
and can only happen in the case of corruption.
I do not have a good intuition about what happens afterwards when the
file system is in such a state. I imagine that this will usually give
an error shortly afterwards, as the opening of the file continues? Is
that right?
–Günther
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] landlock: Constify get_mode_access()
2025-01-10 15:39 ` [PATCH v1 2/2] landlock: Constify get_mode_access() Mickaël Salaün
@ 2025-01-10 16:39 ` Günther Noack
0 siblings, 0 replies; 7+ messages in thread
From: Günther Noack @ 2025-01-10 16:39 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Günther Noack, linux-fsdevel, linux-kernel,
linux-security-module, Paul Moore
On Fri, Jan 10, 2025 at 04:39:14PM +0100, Mickaël Salaün wrote:
> Use __attribute_const__ for get_mode_access().
>
> Cc: Günther Noack <gnoack@google.com>
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> ---
> security/landlock/fs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/security/landlock/fs.c b/security/landlock/fs.c
> index 7adb25150488..f81d0335b825 100644
> --- a/security/landlock/fs.c
> +++ b/security/landlock/fs.c
> @@ -932,7 +932,7 @@ static int current_check_access_path(const struct path *const path,
> return check_access_path(dom, path, access_request);
> }
>
> -static access_mask_t get_mode_access(const umode_t mode)
> +static __attribute_const__ access_mask_t get_mode_access(const umode_t mode)
> {
> switch (mode & S_IFMT) {
> case S_IFLNK:
> --
> 2.47.1
>
Reviewed-by: Günther Noack <gnoack3000@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] landlock: Handle weird files
2025-01-10 16:37 ` [PATCH v1 1/2] landlock: Handle weird files Günther Noack
@ 2025-01-11 15:38 ` Mickaël Salaün
2025-01-15 7:15 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Mickaël Salaün @ 2025-01-11 15:38 UTC (permalink / raw)
To: Günther Noack
Cc: Günther Noack, linux-fsdevel, linux-kernel,
linux-security-module, Paul Moore, Dave Chinner, Kent Overstreet,
syzbot+34b68f850391452207df, syzbot+360866a59e3c80510a62,
Ubisectech Sirius, Brian Foster, linux-bcachefs, linux-xfs
On Fri, Jan 10, 2025 at 05:37:26PM +0100, Günther Noack wrote:
> On Fri, Jan 10, 2025 at 04:39:13PM +0100, Mickaël Salaün wrote:
> > A corrupted filesystem (e.g. bcachefs) might return weird files.
> > Instead of throwing a warning and allowing access to such file, treat
> > them as regular files.
> >
> > Cc: Dave Chinner <david@fromorbit.com>
> > Cc: Günther Noack <gnoack@google.com>
> > Cc: Kent Overstreet <kent.overstreet@linux.dev>
> > Cc: Paul Moore <paul@paul-moore.com>
> > Reported-by: syzbot+34b68f850391452207df@syzkaller.appspotmail.com
> > Closes: https://lore.kernel.org/r/000000000000a65b35061cffca61@google.com
> > Reported-by: syzbot+360866a59e3c80510a62@syzkaller.appspotmail.com
> > Closes: https://lore.kernel.org/r/67379b3f.050a0220.85a0.0001.GAE@google.com
> > Reported-by: Ubisectech Sirius <bugreport@ubisectech.com>
> > Closes: https://lore.kernel.org/r/c426821d-8380-46c4-a494-7008bbd7dd13.bugreport@ubisectech.com
> > Fixes: cb2c7d1a1776 ("landlock: Support filesystem access-control")
> > Signed-off-by: Mickaël Salaün <mic@digikod.net>
> > ---
> > security/landlock/fs.c | 11 +++++------
> > 1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/security/landlock/fs.c b/security/landlock/fs.c
> > index e31b97a9f175..7adb25150488 100644
> > --- a/security/landlock/fs.c
> > +++ b/security/landlock/fs.c
> > @@ -937,10 +937,6 @@ static access_mask_t get_mode_access(const umode_t mode)
> > switch (mode & S_IFMT) {
> > case S_IFLNK:
> > return LANDLOCK_ACCESS_FS_MAKE_SYM;
> > - case 0:
> > - /* A zero mode translates to S_IFREG. */
> > - case S_IFREG:
> > - return LANDLOCK_ACCESS_FS_MAKE_REG;
> > case S_IFDIR:
> > return LANDLOCK_ACCESS_FS_MAKE_DIR;
> > case S_IFCHR:
> > @@ -951,9 +947,12 @@ static access_mask_t get_mode_access(const umode_t mode)
> > return LANDLOCK_ACCESS_FS_MAKE_FIFO;
> > case S_IFSOCK:
> > return LANDLOCK_ACCESS_FS_MAKE_SOCK;
> > + case S_IFREG:
> > + case 0:
> > + /* A zero mode translates to S_IFREG. */
> > default:
> > - WARN_ON_ONCE(1);
> > - return 0;
> > + /* Treats weird files as regular files. */
> > + return LANDLOCK_ACCESS_FS_MAKE_REG;
> > }
> > }
> >
> > --
> > 2.47.1
> >
>
> Reviewed-by: Günther Noack <gnoack3000@gmail.com>
>
> Makes sense to me, since this is enforcing a stronger check than before
> and can only happen in the case of corruption.
>
> I do not have a good intuition about what happens afterwards when the
> file system is in such a state. I imagine that this will usually give
> an error shortly afterwards, as the opening of the file continues? Is
> that right?
I guess it depends on the filesystem implementation. For instance, XFS
returns an error if a weird file is detected [1], whereas bcachefs
ignores it (which is considered a bug, but not fixed yet) [2].
[1] https://lore.kernel.org/all/Zpc46HEacI%2Fwd7Rg@dread.disaster.area/
[2] https://lore.kernel.org/all/4hohnthh54adx35lnxzedop3oxpntpmtygxso4iraiexfdlt4d@6m7ssepvjyar/
>
> –Günther
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] landlock: Handle weird files
2025-01-11 15:38 ` Mickaël Salaün
@ 2025-01-15 7:15 ` Christoph Hellwig
2025-01-15 10:54 ` Christian Brauner
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2025-01-15 7:15 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Günther Noack, Günther Noack, linux-fsdevel,
linux-kernel, linux-security-module, Paul Moore, Dave Chinner,
Kent Overstreet, syzbot+34b68f850391452207df,
syzbot+360866a59e3c80510a62, Ubisectech Sirius, Brian Foster,
linux-bcachefs, linux-xfs
On Sat, Jan 11, 2025 at 04:38:56PM +0100, Mickaël Salaün wrote:
> I guess it depends on the filesystem implementation. For instance, XFS
> returns an error if a weird file is detected [1], whereas bcachefs
> ignores it (which is considered a bug, but not fixed yet) [2].
If a filesyste, returns an invalid mode that's a file system bug and
needs to be fixed there. Warning in a consumer is perfectly fine.
But the right action in that case is indeed not to grant the access.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] landlock: Handle weird files
2025-01-15 7:15 ` Christoph Hellwig
@ 2025-01-15 10:54 ` Christian Brauner
0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2025-01-15 10:54 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Mickaël Salaün, Günther Noack, Günther Noack,
linux-fsdevel, linux-kernel, linux-security-module, Paul Moore,
Dave Chinner, Kent Overstreet, syzbot+34b68f850391452207df,
syzbot+360866a59e3c80510a62, Ubisectech Sirius, Brian Foster,
linux-bcachefs, linux-xfs
On Tue, Jan 14, 2025 at 11:15:42PM -0800, Christoph Hellwig wrote:
> On Sat, Jan 11, 2025 at 04:38:56PM +0100, Mickaël Salaün wrote:
> > I guess it depends on the filesystem implementation. For instance, XFS
> > returns an error if a weird file is detected [1], whereas bcachefs
> > ignores it (which is considered a bug, but not fixed yet) [2].
>
> If a filesyste, returns an invalid mode that's a file system bug and
> needs to be fixed there. Warning in a consumer is perfectly fine.
> But the right action in that case is indeed not to grant the access.
Fyi, anonymous inodes traditionally set the mode to 0 which is
really annoying:
lrwx------ 1 root root 64 15. Jan 11:52 94 -> anon_inode:bpf-prog
> sudo stat -L /proc/1/fd/94
File: /proc/1/fd/94
Size: 0 Blocks: 0 IO Block: 4096 weird file
Device: 0,15 Inode: 4120 Links: 1
Access: (0600/?rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-11-05 17:15:54.404000000 +0100
Modify: 2024-11-05 17:15:54.404000000 +0100
Change: 2024-11-05 17:15:54.404000000 +0100
Birth: -
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-01-15 10:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10 15:39 [PATCH v1 1/2] landlock: Handle weird files Mickaël Salaün
2025-01-10 15:39 ` [PATCH v1 2/2] landlock: Constify get_mode_access() Mickaël Salaün
2025-01-10 16:39 ` Günther Noack
2025-01-10 16:37 ` [PATCH v1 1/2] landlock: Handle weird files Günther Noack
2025-01-11 15:38 ` Mickaël Salaün
2025-01-15 7:15 ` Christoph Hellwig
2025-01-15 10:54 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).