diff mbox series

[mdadm,v1,03/14] DDF: Fix NULL pointer dereference in validate_geometry_ddf()

Message ID 20220609211130.5108-4-logang@deltatee.com (mailing list archive)
State Superseded, archived
Headers show
Series Bug fixes and testing improvments | expand

Commit Message

Logan Gunthorpe June 9, 2022, 9:11 p.m. UTC
A relatively recent patch added a call to validate_geometry() in
Manage_add() that has level=LEVEL_CONTAINER and chunk=NULL.

This causes some ddf tests to segfault which aborts the test suite.

To fix this, avoid dereferencing chunk when the level is
LEVEL_CONTAINER or LEVEL_NONE.

Fixes: 1f5d54a06df0 ("Manage: Call validate_geometry when adding drive to external container")
Cc: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
 super-ddf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Mariusz Tkaczyk June 20, 2022, 2:13 p.m. UTC | #1
On Thu,  9 Jun 2022 15:11:19 -0600
Logan Gunthorpe <logang@deltatee.com> wrote:

> A relatively recent patch added a call to validate_geometry() in
> Manage_add() that has level=LEVEL_CONTAINER and chunk=NULL.
> 
> This causes some ddf tests to segfault which aborts the test suite.
> 
> To fix this, avoid dereferencing chunk when the level is
> LEVEL_CONTAINER or LEVEL_NONE.
> 
> Fixes: 1f5d54a06df0 ("Manage: Call validate_geometry when adding drive to
> external container") Cc: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
> ---
>  super-ddf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/super-ddf.c b/super-ddf.c
> index d3c7a4082046..6bd357cf9b82 100644
> --- a/super-ddf.c
> +++ b/super-ddf.c
> @@ -3369,9 +3369,6 @@ static int validate_geometry_ddf(struct supertype *st,
>  	 * If given BVDs, we make an SVD, changing all the GUIDs in the
> process. */
>  
> -	if (*chunk == UnSet)
> -		*chunk = DEFAULT_CHUNK;
> -
>  	if (level == LEVEL_NONE)
>  		level = LEVEL_CONTAINER;
>  	if (level == LEVEL_CONTAINER) {
> @@ -3381,6 +3378,9 @@ static int validate_geometry_ddf(struct supertype *st,
>  						       freesize, verbose);
>  	}
>  
> +	if (*chunk == UnSet)
> +		*chunk = DEFAULT_CHUNK;
> +
>  	if (!dev) {
>  		mdu_array_info_t array = {
>  			.level = level,

Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
diff mbox series

Patch

diff --git a/super-ddf.c b/super-ddf.c
index d3c7a4082046..6bd357cf9b82 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -3369,9 +3369,6 @@  static int validate_geometry_ddf(struct supertype *st,
 	 * If given BVDs, we make an SVD, changing all the GUIDs in the process.
 	 */
 
-	if (*chunk == UnSet)
-		*chunk = DEFAULT_CHUNK;
-
 	if (level == LEVEL_NONE)
 		level = LEVEL_CONTAINER;
 	if (level == LEVEL_CONTAINER) {
@@ -3381,6 +3378,9 @@  static int validate_geometry_ddf(struct supertype *st,
 						       freesize, verbose);
 	}
 
+	if (*chunk == UnSet)
+		*chunk = DEFAULT_CHUNK;
+
 	if (!dev) {
 		mdu_array_info_t array = {
 			.level = level,