Skip to content

Commit 66be40a

Browse files
author
Mikulas Patocka
committed
dm-verity: fix a memory leak if some arguments are specified multiple times
If some of the arguments "check_at_most_once", "ignore_zero_blocks", "use_fec_from_device", "root_hash_sig_key_desc" were specified more than once on the target line, a memory leak would happen. This commit fixes the memory leak. It also fixes error handling in verity_verify_sig_parse_opt_args. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@vger.kernel.org
1 parent 829451b commit 66be40a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

drivers/md/dm-verity-fec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ int verity_fec_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
593593
(*argc)--;
594594

595595
if (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_DEV)) {
596+
if (v->fec->dev) {
597+
ti->error = "FEC device already specified";
598+
return -EINVAL;
599+
}
596600
r = dm_get_device(ti, arg_value, BLK_OPEN_READ, &v->fec->dev);
597601
if (r) {
598602
ti->error = "FEC device lookup failed";

drivers/md/dm-verity-target.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ static int verity_alloc_most_once(struct dm_verity *v)
11231123
{
11241124
struct dm_target *ti = v->ti;
11251125

1126+
if (v->validated_blocks)
1127+
return 0;
1128+
11261129
/* the bitset can only handle INT_MAX blocks */
11271130
if (v->data_blocks > INT_MAX) {
11281131
ti->error = "device too large to use check_at_most_once";
@@ -1146,6 +1149,9 @@ static int verity_alloc_zero_digest(struct dm_verity *v)
11461149
struct dm_verity_io *io;
11471150
u8 *zero_data;
11481151

1152+
if (v->zero_digest)
1153+
return 0;
1154+
11491155
v->zero_digest = kmalloc(v->digest_size, GFP_KERNEL);
11501156

11511157
if (!v->zero_digest)
@@ -1580,7 +1586,7 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv)
15801586
goto bad;
15811587
}
15821588

1583-
/* Root hash signature is a optional parameter*/
1589+
/* Root hash signature is an optional parameter */
15841590
r = verity_verify_root_hash(root_hash_digest_to_validate,
15851591
strlen(root_hash_digest_to_validate),
15861592
verify_args.sig,

drivers/md/dm-verity-verify-sig.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ int verity_verify_sig_parse_opt_args(struct dm_arg_set *as,
7171
const char *arg_name)
7272
{
7373
struct dm_target *ti = v->ti;
74-
int ret = 0;
74+
int ret;
7575
const char *sig_key = NULL;
7676

77+
if (v->signature_key_desc) {
78+
ti->error = DM_VERITY_VERIFY_ERR("root_hash_sig_key_desc already specified");
79+
return -EINVAL;
80+
}
81+
7782
if (!*argc) {
7883
ti->error = DM_VERITY_VERIFY_ERR("Signature key not specified");
7984
return -EINVAL;
@@ -83,14 +88,18 @@ int verity_verify_sig_parse_opt_args(struct dm_arg_set *as,
8388
(*argc)--;
8489

8590
ret = verity_verify_get_sig_from_key(sig_key, sig_opts);
86-
if (ret < 0)
91+
if (ret < 0) {
8792
ti->error = DM_VERITY_VERIFY_ERR("Invalid key specified");
93+
return ret;
94+
}
8895

8996
v->signature_key_desc = kstrdup(sig_key, GFP_KERNEL);
90-
if (!v->signature_key_desc)
97+
if (!v->signature_key_desc) {
98+
ti->error = DM_VERITY_VERIFY_ERR("Could not allocate memory for signature key");
9199
return -ENOMEM;
100+
}
92101

93-
return ret;
102+
return 0;
94103
}
95104

96105
/*

0 commit comments

Comments
 (0)