]>
Commit | Line | Data |
---|---|---|
9659d8ac GKH |
1 | From b0cc58a25d04160d39a80e436847eaa2fbc5aa09 Mon Sep 17 00:00:00 2001 |
2 | From: Dan Carpenter <error27@gmail.com> | |
3 | Date: Tue, 6 Apr 2010 19:31:26 +0300 | |
4 | Subject: ALSA: mixart: range checking proc file | |
5 | ||
6 | From: Dan Carpenter <error27@gmail.com> | |
7 | ||
8 | commit b0cc58a25d04160d39a80e436847eaa2fbc5aa09 upstream. | |
9 | ||
10 | The original code doesn't take into consideration that the value of | |
11 | MIXART_BA0_SIZE - pos can be less than zero which would lead to a large | |
12 | unsigned value for "count". | |
13 | ||
14 | Also I moved the check that read size is a multiple of 4 bytes below | |
15 | the code that adjusts "count". | |
16 | ||
17 | Signed-off-by: Dan Carpenter <error27@gmail.com> | |
18 | Acked-by: Linus Torvalds <torvalds@linux-foundation.org> | |
19 | Signed-off-by: Takashi Iwai <tiwai@suse.de> | |
20 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
21 | ||
22 | --- | |
23 | sound/pci/mixart/mixart.c | 24 ++++++++++++++---------- | |
24 | 1 file changed, 14 insertions(+), 10 deletions(-) | |
25 | ||
26 | --- a/sound/pci/mixart/mixart.c | |
27 | +++ b/sound/pci/mixart/mixart.c | |
28 | @@ -1161,13 +1161,15 @@ static long snd_mixart_BA0_read(struct s | |
29 | unsigned long count, unsigned long pos) | |
30 | { | |
31 | struct mixart_mgr *mgr = entry->private_data; | |
32 | + unsigned long maxsize; | |
33 | ||
34 | - count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ | |
35 | - if(count <= 0) | |
36 | + if (pos >= MIXART_BA0_SIZE) | |
37 | return 0; | |
38 | - if(pos + count > MIXART_BA0_SIZE) | |
39 | - count = (long)(MIXART_BA0_SIZE - pos); | |
40 | - if(copy_to_user_fromio(buf, MIXART_MEM( mgr, pos ), count)) | |
41 | + maxsize = MIXART_BA0_SIZE - pos; | |
42 | + if (count > maxsize) | |
43 | + count = maxsize; | |
44 | + count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ | |
45 | + if (copy_to_user_fromio(buf, MIXART_MEM(mgr, pos), count)) | |
46 | return -EFAULT; | |
47 | return count; | |
48 | } | |
49 | @@ -1180,13 +1182,15 @@ static long snd_mixart_BA1_read(struct s | |
50 | unsigned long count, unsigned long pos) | |
51 | { | |
52 | struct mixart_mgr *mgr = entry->private_data; | |
53 | + unsigned long maxsize; | |
54 | ||
55 | - count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ | |
56 | - if(count <= 0) | |
57 | + if (pos > MIXART_BA1_SIZE) | |
58 | return 0; | |
59 | - if(pos + count > MIXART_BA1_SIZE) | |
60 | - count = (long)(MIXART_BA1_SIZE - pos); | |
61 | - if(copy_to_user_fromio(buf, MIXART_REG( mgr, pos ), count)) | |
62 | + maxsize = MIXART_BA1_SIZE - pos; | |
63 | + if (count > maxsize) | |
64 | + count = maxsize; | |
65 | + count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ | |
66 | + if (copy_to_user_fromio(buf, MIXART_REG(mgr, pos), count)) | |
67 | return -EFAULT; | |
68 | return count; | |
69 | } |