Skip to contentSkip to conversation

exofs: add a cap on the memcpy() size

PATCH In review Dan Carpenter 2 participants 6 messages Jan 30, 2012 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exofs: add a cap on the memcpy() size

This data comes from the device, so probably it's fairly trustworthy but it makes the static checkers happy if we check it.

fs/exofs/super.c +2 -0
index d22cd16..755812a 100644
@@ -529,6 +529,8 @@ static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev,
 			     struct osd_dev_info *odi)
 {
 	odi->systemid_len = le32_to_cpu(dt_dev->systemid_len);
+	if (odi->systemid_len > OSD_SYSTEMID_LEN)
+		return -EINVAL;
 	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
 
 	odi->osdname_len = le32_to_cpu(dt_dev->osdname_len);
#1 lore raw
Quoted 10 lines · Dan Carpenter

This data comes from the device, so probably it's fairly trustworthy but it makes the static checkers happy if we check it.

fs/exofs/super.c +0 -0
index d22cd16..755812a 100644

fs/exofs/super.c static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev, · line 536

Quoted 8 lines
fs/exofs/super.c +2 -0
@@ -529,6 +529,8 @@ static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev,
 			     struct osd_dev_info *odi)
 {
 	odi->systemid_len = le32_to_cpu(dt_dev->systemid_len);
+	if (odi->systemid_len > OSD_SYSTEMID_LEN)
+		return -EINVAL;
 	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
 
 	odi->osdname_len = le32_to_cpu(dt_dev->osdname_len);

Hi Dan

I was going over this code and for the life of me I can't remember why I have dt_dev->systemid_len at all. The ->systemid field is just a constant 20 bytes buffer that is always there. at all ends of the spectrum. (Including user-mode mkfs.exofs)

I think my thought was that dt_dev->systemid_len could be either 20 or zero, for ignoring it.

I think I'd like something like:
- memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
+ if (likely(odi->systemid_len))
+ memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN);

Which should also make the static checkers happy. What do you think?

Thanks
Boaz

#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Boaz Harrosh

I think I'd like something like:

(quoted diff) +2 -1
-  	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
+	if (likely(odi->systemid_len))
+ 		memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN);

Which should also make the static checkers happy. What do you think?

Sounds good to me.

regards,
dan carpenter

#3 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter
Quoted 5 lines · Boaz Harrosh

I think I'd like something like:

(quoted diff) +2 -1
-  	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
+	if (likely(odi->systemid_len))
+ 		memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN);
Quoted 8 lines
Quoted 2 lines

Which should also make the static checkers happy. What do you think?

Sounds good to me.

regards,
dan carpenter

OK I'll make a patch. Please send your review-by

Thanks for catching it
Boaz

#4 lore raw
In reply to Dan Carpenter
Quoted 12 lines · Boaz Harrosh
Quoted 11 lines · Dan Carpenter
Quoted 7 lines · Boaz Harrosh

I think I'd like something like:

(quoted diff) +2 -1
-  	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
+	if (likely(odi->systemid_len))
+ 		memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN);

Which should also make the static checkers happy. What do you think?

Sounds good to me.

Quoted 5 lines
Quoted 3 lines

regards,
dan carpenter

OK I'll make a patch. Please send your review-by

Could you give me a Reported-by cookie instead? No one pays any special attention to Reviewed-by tags when they come from newbies like me... :P

regards,
dan carpenter

#5 lore raw
In reply to Dan Carpenter
Quoted 17 lines · Dan Carpenter
Quoted 16 lines · Boaz Harrosh
Quoted 14 lines · Dan Carpenter
Quoted 7 lines · Boaz Harrosh

I think I'd like something like:

(quoted diff) +2 -1
-  	memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len);
+	if (likely(odi->systemid_len))
+ 		memcpy(odi->systemid, dt_dev->systemid, OSD_SYSTEMID_LEN);

Which should also make the static checkers happy. What do you think?

Sounds good to me.

regards,
dan carpenter

Quoted 9 lines
Quoted 1 line

OK I'll make a patch. Please send your review-by

Could you give me a Reported-by cookie instead? No one pays any special attention to Reviewed-by tags when they come from newbies like me... :P

regards,
dan carpenter

Sure, yes

Boaz