ALSA: info: Avoid leaking kernel memory
PATCH 1/2 ALSA: info: Avoid leaking kernel memory
Make sure that the allocated buffer for reading the proc file won't expose the uncleared kernel memory.
--- sound/core/info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/info.c +2 -2
@@ -89,7 +89,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,char *nbuf; nsize =PAGE_ALIGN (nsize); - nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL ); + nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL | __GFP_ZERO);if (! nbuf)return -ENOMEM ;
@@ -353,7 +353,7 @@ static int snd_info_entry_open(struct inode *inode, struct file *file) goto __nomem; data->rbuffer = buffer; buffer->len =PAGE_SIZE ; - buffer->buffer =kmalloc (buffer->len,GFP_KERNEL ); + buffer->buffer =kzalloc (buffer->len,GFP_KERNEL );if (buffer->buffer ==NULL ) goto __nomem; }
Signature · 1 line
1.8.1.4
PATCH 2/2 ALSA: info: Small refactoring and a sanity check in snd_info_get_line()
--- sound/core/info.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
sound/core/info.c +8 -13
@@ -700,26 +700,21 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) {int c =-1 ; +if (snd_BUG_ON (!buffer || !buffer->buffer)) +return 1 ;if (len <=0 || buffer->stop || buffer->error)return 1 ; -while (--len >0 ) { +while (!buffer->stop) { c = buffer->buffer[buffer->curr++]; -if (c =='\n' ) { -if (buffer->curr >= buffer->size) - buffer->stop =1 ; -break ; - } - *line++ = c; -if (buffer->curr >= buffer->size) { +if (buffer->curr >= buffer->size) buffer->stop =1 ; +if (c =='\n' )break ; +if (len) { + len--; + *line++ = c; } } -while (c !='\n' && !buffer->stop) { - c = buffer->buffer[buffer->curr++]; -if (buffer->curr >= buffer->size) - buffer->stop =1 ; - } *line ='\0' ;return 0 ; }
Signature · 1 line
1.8.1.4
Quoted 2 lines · Takashi Iwai
Make sure that the allocated buffer for reading the proc file won't expose the uncleared kernel memory.
This should go to stable too, due to the security implications of leaking possibly sensitive information to userspace?
Quoted 29 lines
Signed-off-by Takashi Iwai <[email protected]>--- sound/core/info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/core/info.c +2
-2@@ -89,7 +89,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,char *nbuf; nsize =PAGE_ALIGN (nsize); - nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL ); + nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL | __GFP_ZERO);if (! nbuf)return -ENOMEM ;@@ -353,7 +353,7 @@ static int snd_info_entry_open(struct inode *inode, struct file *file) goto __nomem; data->rbuffer = buffer; buffer->len =PAGE_SIZE ; - buffer->buffer =kmalloc (buffer->len,GFP_KERNEL ); + buffer->buffer =kzalloc (buffer->len,GFP_KERNEL );if (buffer->buffer ==NULL ) goto __nomem; }
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
At Thu, 14 Mar 2013 07:15:28 +0100,
Quoted 7 lines · David Henningsson
Quoted 2 lines · Takashi Iwai
Make sure that the allocated buffer for reading the proc file won't expose the uncleared kernel memory.
This should go to stable too, due to the security implications of leaking possibly sensitive information to userspace?
It's no problem as long as the driver formats the proc output properly via snd_iprintf(), thus no actual exposure happens in the codes we have for now, AFAIK.
The patch is just to be sure on the ground level.
Takashi
Quoted 37 lines
Quoted 30 lines
Signed-off-by Takashi Iwai <[email protected]>--- sound/core/info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/core/info.c +2
-2@@ -89,7 +89,7 @@ static int resize_info_buffer(struct snd_info_buffer *buffer,char *nbuf; nsize =PAGE_ALIGN (nsize); - nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL ); + nbuf =krealloc (buffer->buffer, nsize,GFP_KERNEL | __GFP_ZERO);if (! nbuf)return -ENOMEM ;@@ -353,7 +353,7 @@ static int snd_info_entry_open(struct inode *inode, struct file *file) goto __nomem; data->rbuffer = buffer; buffer->len =PAGE_SIZE ; - buffer->buffer =kmalloc (buffer->len,GFP_KERNEL ); + buffer->buffer =kzalloc (buffer->len,GFP_KERNEL );if (buffer->buffer ==NULL ) goto __nomem; }Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic