[v3,3/3] ovl: validate superblock in OVL_FS()

Message ID 20230521082813.17025-4-andrea.righi@canonical.com
State New
Headers
Series overlayfs: debugging check for valid superblock |

Commit Message

Andrea Righi May 21, 2023, 8:28 a.m. UTC
  When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make
sure that OVL_FS() is always used with a valid overlayfs superblock.
Otherwise trigger a WARN_ON_ONCE().

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---
 fs/overlayfs/ovl_entry.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

Miklos Szeredi July 24, 2023, 2:43 p.m. UTC | #1
On Sun, 21 May 2023 at 10:28, Andrea Righi <andrea.righi@canonical.com> wrote:
>
> When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make
> sure that OVL_FS() is always used with a valid overlayfs superblock.
> Otherwise trigger a WARN_ON_ONCE().
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> ---
>  fs/overlayfs/ovl_entry.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
> index b32c38fdf3c7..e156649d9c71 100644
> --- a/fs/overlayfs/ovl_entry.h
> +++ b/fs/overlayfs/ovl_entry.h
> @@ -97,8 +97,20 @@ static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
>
>  extern struct file_system_type ovl_fs_type;
>
> +static inline bool is_ovl_fs_sb(struct super_block *sb)
> +{
> +       return sb->s_type == &ovl_fs_type;
> +}
> +
> +#ifdef CONFIG_OVERLAY_FS_DEBUG
> +#define OVL_VALIDATE_SB(__sb)  WARN_ON_ONCE(!is_ovl_fs_sb(__sb))
> +#else
> +#define OVL_VALIDATE_SB(__sb)
> +#endif
> +
>  static inline struct ovl_fs *OVL_FS(struct super_block *sb)
>  {
> +       OVL_VALIDATE_SB(sb);

This could be written simply and naturally:

    if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
         WARN_ON_ONCE(sb->s_type != &ovl_fs_type)

Thanks,
Miklos
  
Amir Goldstein Aug. 11, 2023, 9:14 a.m. UTC | #2
On Mon, Jul 24, 2023 at 5:43 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Sun, 21 May 2023 at 10:28, Andrea Righi <andrea.righi@canonical.com> wrote:
> >
> > When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make
> > sure that OVL_FS() is always used with a valid overlayfs superblock.
> > Otherwise trigger a WARN_ON_ONCE().
> >
> > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> > ---
> >  fs/overlayfs/ovl_entry.h | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
> > index b32c38fdf3c7..e156649d9c71 100644
> > --- a/fs/overlayfs/ovl_entry.h
> > +++ b/fs/overlayfs/ovl_entry.h
> > @@ -97,8 +97,20 @@ static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
> >
> >  extern struct file_system_type ovl_fs_type;
> >
> > +static inline bool is_ovl_fs_sb(struct super_block *sb)
> > +{
> > +       return sb->s_type == &ovl_fs_type;
> > +}
> > +
> > +#ifdef CONFIG_OVERLAY_FS_DEBUG
> > +#define OVL_VALIDATE_SB(__sb)  WARN_ON_ONCE(!is_ovl_fs_sb(__sb))
> > +#else
> > +#define OVL_VALIDATE_SB(__sb)
> > +#endif
> > +
> >  static inline struct ovl_fs *OVL_FS(struct super_block *sb)
> >  {
> > +       OVL_VALIDATE_SB(sb);
>
> This could be written simply and naturally:
>
>     if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
>          WARN_ON_ONCE(sb->s_type != &ovl_fs_type)
>

Andrea,

There is an inherent challenge with a cleanup series like this one
that touches many functions to avoid merge conflicts with other
devel branches. I did not try, but I expect there are conflicts
with the current overlayfs-next branch.

I also see at least one new direct reference of sb->s_fs_info
in ovl_maybe_validate_verity().

Please make sure to base your next submission on overlayfs-next
branch from git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git.

Once you do that, we could apply your patches to overlayfs-next
so they won't get stale again.

Thanks,
Amir.
  
Amir Goldstein Aug. 12, 2023, 4:26 p.m. UTC | #3
On Fri, Aug 11, 2023 at 12:14 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Mon, Jul 24, 2023 at 5:43 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> >
> > On Sun, 21 May 2023 at 10:28, Andrea Righi <andrea.righi@canonical.com> wrote:
> > >
> > > When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make
> > > sure that OVL_FS() is always used with a valid overlayfs superblock.
> > > Otherwise trigger a WARN_ON_ONCE().
> > >
> > > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > > Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> > > ---
> > >  fs/overlayfs/ovl_entry.h | 12 ++++++++++++
> > >  1 file changed, 12 insertions(+)
> > >
> > > diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
> > > index b32c38fdf3c7..e156649d9c71 100644
> > > --- a/fs/overlayfs/ovl_entry.h
> > > +++ b/fs/overlayfs/ovl_entry.h
> > > @@ -97,8 +97,20 @@ static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
> > >
> > >  extern struct file_system_type ovl_fs_type;
> > >
> > > +static inline bool is_ovl_fs_sb(struct super_block *sb)
> > > +{
> > > +       return sb->s_type == &ovl_fs_type;
> > > +}
> > > +
> > > +#ifdef CONFIG_OVERLAY_FS_DEBUG
> > > +#define OVL_VALIDATE_SB(__sb)  WARN_ON_ONCE(!is_ovl_fs_sb(__sb))
> > > +#else
> > > +#define OVL_VALIDATE_SB(__sb)
> > > +#endif
> > > +
> > >  static inline struct ovl_fs *OVL_FS(struct super_block *sb)
> > >  {
> > > +       OVL_VALIDATE_SB(sb);
> >
> > This could be written simply and naturally:
> >
> >     if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
> >          WARN_ON_ONCE(sb->s_type != &ovl_fs_type)
> >
>
> Andrea,
>
> There is an inherent challenge with a cleanup series like this one
> that touches many functions to avoid merge conflicts with other
> devel branches. I did not try, but I expect there are conflicts
> with the current overlayfs-next branch.
>
> I also see at least one new direct reference of sb->s_fs_info
> in ovl_maybe_validate_verity().
>
> Please make sure to base your next submission on overlayfs-next
> branch from git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git.
>
> Once you do that, we could apply your patches to overlayfs-next
> so they won't get stale again.

Nevermind, I had rebased overlayfs-next, so already applied your
patches with the needed conflict resolutions and addressed Miklos' comment.

Thanks,
Amir.
  
Andrea Righi Aug. 13, 2023, 7:31 a.m. UTC | #4
On Sat, Aug 12, 2023 at 07:26:01PM +0300, Amir Goldstein wrote:
> On Fri, Aug 11, 2023 at 12:14 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Mon, Jul 24, 2023 at 5:43 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> > >
> > > On Sun, 21 May 2023 at 10:28, Andrea Righi <andrea.righi@canonical.com> wrote:
> > > >
> > > > When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make
> > > > sure that OVL_FS() is always used with a valid overlayfs superblock.
> > > > Otherwise trigger a WARN_ON_ONCE().
> > > >
> > > > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > > > Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> > > > ---
> > > >  fs/overlayfs/ovl_entry.h | 12 ++++++++++++
> > > >  1 file changed, 12 insertions(+)
> > > >
> > > > diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
> > > > index b32c38fdf3c7..e156649d9c71 100644
> > > > --- a/fs/overlayfs/ovl_entry.h
> > > > +++ b/fs/overlayfs/ovl_entry.h
> > > > @@ -97,8 +97,20 @@ static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
> > > >
> > > >  extern struct file_system_type ovl_fs_type;
> > > >
> > > > +static inline bool is_ovl_fs_sb(struct super_block *sb)
> > > > +{
> > > > +       return sb->s_type == &ovl_fs_type;
> > > > +}
> > > > +
> > > > +#ifdef CONFIG_OVERLAY_FS_DEBUG
> > > > +#define OVL_VALIDATE_SB(__sb)  WARN_ON_ONCE(!is_ovl_fs_sb(__sb))
> > > > +#else
> > > > +#define OVL_VALIDATE_SB(__sb)
> > > > +#endif
> > > > +
> > > >  static inline struct ovl_fs *OVL_FS(struct super_block *sb)
> > > >  {
> > > > +       OVL_VALIDATE_SB(sb);
> > >
> > > This could be written simply and naturally:
> > >
> > >     if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
> > >          WARN_ON_ONCE(sb->s_type != &ovl_fs_type)
> > >
> >
> > Andrea,
> >
> > There is an inherent challenge with a cleanup series like this one
> > that touches many functions to avoid merge conflicts with other
> > devel branches. I did not try, but I expect there are conflicts
> > with the current overlayfs-next branch.
> >
> > I also see at least one new direct reference of sb->s_fs_info
> > in ovl_maybe_validate_verity().
> >
> > Please make sure to base your next submission on overlayfs-next
> > branch from git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git.
> >
> > Once you do that, we could apply your patches to overlayfs-next
> > so they won't get stale again.
> 
> Nevermind, I had rebased overlayfs-next, so already applied your
> patches with the needed conflict resolutions and addressed Miklos' comment.

Sorry for the late response, I was on vacation (with a poor internet
connection). However, it looks like there's not much to do for me at
this point, thanks for taking care of this! :)

-Andrea

> 
> Thanks,
> Amir.
  

Patch

diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index b32c38fdf3c7..e156649d9c71 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -97,8 +97,20 @@  static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
 
 extern struct file_system_type ovl_fs_type;
 
+static inline bool is_ovl_fs_sb(struct super_block *sb)
+{
+	return sb->s_type == &ovl_fs_type;
+}
+
+#ifdef CONFIG_OVERLAY_FS_DEBUG
+#define OVL_VALIDATE_SB(__sb)	WARN_ON_ONCE(!is_ovl_fs_sb(__sb))
+#else
+#define OVL_VALIDATE_SB(__sb)
+#endif
+
 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
 {
+	OVL_VALIDATE_SB(sb);
 	return (struct ovl_fs *)sb->s_fs_info;
 }