ovl: don't allow datadir only
authorMiklos Szeredi <mszeredi@redhat.com>
Mon, 10 Feb 2025 14:11:22 +0000 (15:11 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:47:53 +0000 (10:47 +0200)
commit eb3a04a8516ee9b5174379306f94279fc90424c4 upstream.

In theory overlayfs could support upper layer directly referring to a data
layer, but there's no current use case for this.

Originally, when data-only layers were introduced, this wasn't allowed,
only introduced by the "datadir+" feature, but without actually handling
this case, resulting in an Oops.

Fix by disallowing datadir without lowerdir.

Reported-by: Giuseppe Scrivano <gscrivan@redhat.com>
Fixes: 24e16e385f22 ("ovl: add support for appending lowerdirs one by one")
Cc: <stable@vger.kernel.org> # v6.7
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Alexander Larsson <alexl@redhat.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/overlayfs/super.c

index fe511192f83cb0dd6b60f9078be64e38bc271c5c..87a36c6eea5f36186a60f1be06eaeecc5d939fc3 100644 (file)
@@ -1119,6 +1119,11 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
                return ERR_PTR(-EINVAL);
        }
 
+       if (ctx->nr == ctx->nr_data) {
+               pr_err("at least one non-data lowerdir is required\n");
+               return ERR_PTR(-EINVAL);
+       }
+
        err = -EINVAL;
        for (i = 0; i < ctx->nr; i++) {
                l = &ctx->lower[i];