@@ -346,7 +346,7 @@ static void ovl_parse_param_drop_lowerdir(struct ovl_fs_context *ctx)
346346/*
347347 * Parse lowerdir= mount option:
348348 *
349- * (1) lowerdir=/lower1:/lower2:/lower3::/data1::/data2
349+ * e.g.: lowerdir=/lower1:/lower2:/lower3::/data1::/data2
350350 * Set "/lower1", "/lower2", and "/lower3" as lower layers and
351351 * "/data1" and "/data2" as data lower layers. Any existing lower
352352 * layers are replaced.
@@ -356,20 +356,20 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
356356 int err ;
357357 struct ovl_fs_context * ctx = fc -> fs_private ;
358358 struct ovl_fs_context_layer * l ;
359- char * dup = NULL , * dup_iter ;
359+ char * dup = NULL , * iter ;
360360 ssize_t nr_lower = 0 , nr = 0 , nr_data = 0 ;
361- bool append = false, data_layer = false;
361+ bool data_layer = false;
362362
363363 /*
364364 * Ensure we're backwards compatible with mount(2)
365365 * by allowing relative paths.
366366 */
367367
368368 /* drop all existing lower layers */
369- if (!* name ) {
370- ovl_parse_param_drop_lowerdir (ctx );
369+ ovl_parse_param_drop_lowerdir (ctx );
370+
371+ if (!* name )
371372 return 0 ;
372- }
373373
374374 if (* name == ':' ) {
375375 pr_err ("cannot append lower layer" );
@@ -385,36 +385,11 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
385385 if (nr_lower < 0 )
386386 goto out_err ;
387387
388- if ((nr_lower > OVL_MAX_STACK ) ||
389- (append && (size_add (ctx -> nr , nr_lower ) > OVL_MAX_STACK ))) {
388+ if (nr_lower > OVL_MAX_STACK ) {
390389 pr_err ("too many lower directories, limit is %d\n" , OVL_MAX_STACK );
391390 goto out_err ;
392391 }
393392
394- if (!append )
395- ovl_parse_param_drop_lowerdir (ctx );
396-
397- /*
398- * (1) append
399- *
400- * We want nr <= nr_lower <= capacity We know nr > 0 and nr <=
401- * capacity. If nr == 0 this wouldn't be append. If nr +
402- * nr_lower is <= capacity then nr <= nr_lower <= capacity
403- * already holds. If nr + nr_lower exceeds capacity, we realloc.
404- *
405- * (2) replace
406- *
407- * Ensure we're backwards compatible with mount(2) which allows
408- * "lowerdir=/a:/b:/c,lowerdir=/d:/e:/f" causing the last
409- * specified lowerdir mount option to win.
410- *
411- * We want nr <= nr_lower <= capacity We know either (i) nr == 0
412- * or (ii) nr > 0. We also know nr_lower > 0. The capacity
413- * could've been changed multiple times already so we only know
414- * nr <= capacity. If nr + nr_lower > capacity we realloc,
415- * otherwise nr <= nr_lower <= capacity holds already.
416- */
417- nr_lower += ctx -> nr ;
418393 if (nr_lower > ctx -> capacity ) {
419394 err = - ENOMEM ;
420395 l = krealloc_array (ctx -> lower , nr_lower , sizeof (* ctx -> lower ),
@@ -426,41 +401,17 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
426401 ctx -> capacity = nr_lower ;
427402 }
428403
429- /*
430- * (3) By (1) and (2) we know nr <= nr_lower <= capacity.
431- * (4) If ctx->nr == 0 => replace
432- * We have verified above that the lowerdir mount option
433- * isn't an append, i.e., the lowerdir mount option
434- * doesn't start with ":" or "::".
435- * (4.1) The lowerdir mount options only contains regular lower
436- * layers ":".
437- * => Nothing to verify.
438- * (4.2) The lowerdir mount options contains regular ":" and
439- * data "::" layers.
440- * => We need to verify that data lower layers "::" aren't
441- * followed by regular ":" lower layers
442- * (5) If ctx->nr > 0 => append
443- * We know that there's at least one regular layer
444- * otherwise we would've failed when parsing the previous
445- * lowerdir mount option.
446- * (5.1) The lowerdir mount option is a regular layer ":" append
447- * => We need to verify that no data layers have been
448- * specified before.
449- * (5.2) The lowerdir mount option is a data layer "::" append
450- * We know that there's at least one regular layer or
451- * other data layers. => There's nothing to verify.
452- */
453- dup_iter = dup ;
454- for (nr = ctx -> nr ; nr < nr_lower ; nr ++ ) {
455- l = & ctx -> lower [nr ];
404+ iter = dup ;
405+ l = ctx -> lower ;
406+ for (nr = 0 ; nr < nr_lower ; nr ++ , l ++ ) {
456407 memset (l , 0 , sizeof (* l ));
457408
458- err = ovl_mount_dir (dup_iter , & l -> path , false);
409+ err = ovl_mount_dir (iter , & l -> path , false);
459410 if (err )
460411 goto out_put ;
461412
462413 err = - ENOMEM ;
463- l -> name = kstrdup (dup_iter , GFP_KERNEL_ACCOUNT );
414+ l -> name = kstrdup (iter , GFP_KERNEL_ACCOUNT );
464415 if (!l -> name )
465416 goto out_put ;
466417
@@ -472,8 +423,8 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
472423 break ;
473424
474425 err = - EINVAL ;
475- dup_iter = strchr (dup_iter , '\0' ) + 1 ;
476- if (* dup_iter ) {
426+ iter = strchr (iter , '\0' ) + 1 ;
427+ if (* iter ) {
477428 /*
478429 * This is a regular layer so we require that
479430 * there are no data layers.
@@ -489,29 +440,15 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
489440
490441 /* This is a data lower layer. */
491442 data_layer = true;
492- dup_iter ++ ;
443+ iter ++ ;
493444 }
494445 ctx -> nr = nr_lower ;
495446 ctx -> nr_data += nr_data ;
496447 kfree (dup );
497448 return 0 ;
498449
499450out_put :
500- /*
501- * We know nr >= ctx->nr < nr_lower. If we failed somewhere
502- * we want to undo until nr == ctx->nr. This is correct for
503- * both ctx->nr == 0 and ctx->nr > 0.
504- */
505- for (; nr >= ctx -> nr ; nr -- ) {
506- l = & ctx -> lower [nr ];
507- kfree (l -> name );
508- l -> name = NULL ;
509- path_put (& l -> path );
510-
511- /* don't overflow */
512- if (nr == 0 )
513- break ;
514- }
451+ ovl_parse_param_drop_lowerdir (ctx );
515452
516453out_err :
517454 kfree (dup );
0 commit comments