Skip to contentSkip to conversation

dvb: copy_from_user checks

PATCH RESEND In review Alan Cox 2 participants 2 messages Feb 18, 2010 – Feb 19, 2010 Media (V4L/DVB)

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH RESEND 1/1 dvb: copy_from_user checks

I don't believe the frag count can ever get loaded with a negative value even with the -2 but neither the compiler (nor I ;)) can prove it so keep us both happy.

---

 drivers/media/dvb/dvb-core/dvb_ca_en50221.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-core/dvb_ca_en50221.c +3 -1
index cb22da5..2cf03e9 100644
@@ -1280,7 +1280,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 	u8 slot, connection_id;
 	int status;
 	u8 fragbuf[HOST_LINK_BUF_SIZE];
-	int fragpos = 0;
+	unsigned int fragpos = 0;
 	int fraglen;
 	unsigned long timeout;
 	int written;
@@ -1308,6 +1308,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 		fraglen = ca->slot_info[slot].link_buf_size - 2;
 		if ((count - fragpos) < fraglen)
 			fraglen = count - fragpos;
+		if (fraglen < 0)
+		        fraglen = 0;
 
 		fragbuf[0] = connection_id;
 		fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00;
#1 lore raw
Quoted 25 lines · Alan Cox

I don't believe the frag count can ever get loaded with a negative value even with the -2 but neither the compiler (nor I ;)) can prove it so keep us both happy.

---

 drivers/media/dvb/dvb-core/dvb_ca_en50221.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-core/dvb_ca_en50221.c +1 -1
index cb22da5..2cf03e9 100644
@@ -1280,7 +1280,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 	u8 slot, connection_id;
 	int status;
 	u8 fragbuf[HOST_LINK_BUF_SIZE];
-	int fragpos = 0;
+	unsigned int fragpos = 0;
 	int fraglen;
 	unsigned long timeout;
 	int written;

drivers/media/dvb/dvb-core/dvb_ca_en50221.c static ssize_t dvb_ca_en50221_io_write(struct file *file, · line 1312

Quoted 5 lines
drivers/media/dvb/dvb-core/dvb_ca_en50221.c +2 -0
@@ -1308,6 +1308,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 		fraglen = ca->slot_info[slot].link_buf_size - 2;
 		if ((count - fragpos) < fraglen)
 			fraglen = count - fragpos;
+		if (fraglen < 0)
+		        fraglen = 0;

If fragpos is unsigned int, then the < fraglen comparison is going to be unsigned, which is probably not what you want either, is it?

OG.