dm-flakey: Use as->argc instead of argc
PATCH 1/2 dm-flakey: Use as->argc instead of argc
From: Goldwyn Rodrigues <[email protected]>
Since arguments are divided in argument sets, using argc fails corrupt_bio_byte because it is zero. We should be using as->argc to check the number of arguments.
--- drivers/md/dm-flakey.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/md/dm-flakey.c +1 -5
@@ -105,7 +105,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,* corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags> */ if (!strcasecmp (arg_name,"corrupt_bio_byte" )) { -if (!argc) { +if (as->argc <4 ) { ti->error ="Feature corrupt_bio_byte requires parameters" ;return -EINVAL ; }
@@ -113,7 +113,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +1 , as, &fc->corrupt_bio_byte, &ti->error);if (r)return r; - argc--;/* * Direction r or w?
@@ -127,7 +126,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, ti->error ="Invalid corrupt bio direction (r or w)" ;return -EINVAL ; } - argc--;/* * Value of byte (0-255) to write in place of correct one.
@@ -135,7 +133,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +2 , as, &fc->corrupt_bio_value, &ti->error);if (r)return r; - argc--;/* * Only corrupt bios with these flags set.
@@ -143,7 +140,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +3 , as, &fc->corrupt_bio_flags, &ti->error);if (r)return r; - argc--;continue ; }
Signature · 1 line
2.14.2
PATCH 2/2 dm-flakey: Check for null arg_name
From: Goldwyn Rodrigues <[email protected]>
One can crash dm-flakey by specifying more number of feature arguments than the number of features supplied. Checking for null in arg_name avoids this.
dmsetup create flakey-test --table "0 66076080 flakey /dev/sdb9 0 0 180 2 \drop_writes"
--- drivers/md/dm-flakey.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/dm-flakey.c +5 -0
@@ -70,6 +70,11 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, arg_name =dm_shift_arg (as); argc--; +if (!arg_name) { + ti->error ="Insufficient feature arguments" ; +return -EINVAL ; + } +/* * drop_writes */
Signature · 1 line
2.14.2
Quoted 49 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Since arguments are divided in argument sets, using argc fails
corrupt_bio_bytebecause it is zero. We should be usingas->argcto check the number of arguments.Signed-off-by Goldwyn Rodrigues <[email protected]>--- drivers/md/dm-flakey.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/md/dm-flakey.c +1
-4@@ -105,7 +105,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,* corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags> */ if (!strcasecmp (arg_name,"corrupt_bio_byte" )) { -if (!argc) { +if (as->argc <4 ) { ti->error ="Feature corrupt_bio_byte requires parameters" ;return -EINVAL ; }@@ -113,7 +113,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +1 , as, &fc->corrupt_bio_byte, &ti->error);if (r)return r; - argc--;/* * Direction r or w? @@ -127,7 +126,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, ti->error ="Invalid corrupt bio direction (r or w)" ;return -EINVAL ; } - argc--;/* * Value of byte (0-255) to write in place of correct one. @@ -135,7 +133,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +2 , as, &fc->corrupt_bio_value, &ti->error);if (r)return r; - argc--;/* * Only corrupt bios with these flags set.
drivers/md/dm-flakey.c static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, · line 145
Quoted 7 lines
drivers/md/dm-flakey.c +0
-1@@ -143,7 +140,6 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +3 , as, &fc->corrupt_bio_flags, &ti->error);if (r)return r; - argc--;continue ; }
This is wrong. The outer control loop is using argc. Therefore it needs to be managed.
But I'll grant you that the check should be "argc < 4" rather than the less precise "!argc" check.
Mike