Skip to content

Commit 37f32f5

Browse files
amir73ilea1davis
andcommitted
ovl: fix memory leak in ovl_parse_param()
On failure to parse parameters in ovl_parse_param_lowerdir(), it is necessary to update ctx->nr with the correct nr before using ovl_reset_lowerdirs() to release l->name. Reported-and-tested-by: syzbot+26eedf3631650972f17c@syzkaller.appspotmail.com Fixes: c835110 ("ovl: remove unused code in lowerdir param parsing") Co-authored-by: Edward Adam Davis <eadavis@qq.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
1 parent b28060d commit 37f32f5

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

fs/overlayfs/params.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
430430
struct ovl_fs_context *ctx = fc->fs_private;
431431
struct ovl_fs_context_layer *l;
432432
char *dup = NULL, *iter;
433-
ssize_t nr_lower = 0, nr = 0, nr_data = 0;
433+
ssize_t nr_lower, nr;
434434
bool data_layer = false;
435435

436436
/*
@@ -482,6 +482,7 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
482482
iter = dup;
483483
l = ctx->lower;
484484
for (nr = 0; nr < nr_lower; nr++, l++) {
485+
ctx->nr++;
485486
memset(l, 0, sizeof(*l));
486487

487488
err = ovl_mount_dir(iter, &l->path);
@@ -498,10 +499,10 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
498499
goto out_put;
499500

500501
if (data_layer)
501-
nr_data++;
502+
ctx->nr_data++;
502503

503504
/* Calling strchr() again would overrun. */
504-
if ((nr + 1) == nr_lower)
505+
if (ctx->nr == nr_lower)
505506
break;
506507

507508
err = -EINVAL;
@@ -511,7 +512,7 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
511512
* This is a regular layer so we require that
512513
* there are no data layers.
513514
*/
514-
if ((ctx->nr_data + nr_data) > 0) {
515+
if (ctx->nr_data > 0) {
515516
pr_err("regular lower layers cannot follow data lower layers");
516517
goto out_put;
517518
}
@@ -524,8 +525,6 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
524525
data_layer = true;
525526
iter++;
526527
}
527-
ctx->nr = nr_lower;
528-
ctx->nr_data += nr_data;
529528
kfree(dup);
530529
return 0;
531530

0 commit comments

Comments
 (0)