Skip to contentSkip to conversation

drivers/s390/char/keyboard.c kernel stack infoleak

PATCH sohu0106 3 participants 4 messages Aug 3, 2017 – Aug 5, 2017 1 message not in the archive s390

lore
Share & tools
lore

sohu0106

author
#0 lore raw

The stack object "kbdiacr" has a total size of 4 bytes. Its last 1 bytes are padding bytes after "result" which are not initialized and leaked to userland via "copy_to_user".

keyboard.c +2 -0
index ba0e4f9..76a6d35 100644
@@ -480,6 +480,8 @@ int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg)
                struct kbdiacr diacr;
                int i;
 
+               memset( &diacr, 0, sizeof(struct kbdiacr) );
+
                if (put_user(kbd->accent_table_size, &a->kb_cnt))
                        return -EFAULT;
                for (i = 0; i < kbd->accent_table_size; i++) {
#1 lore raw

Hi,

Quoted 9 lines · On 03.08.2017 15:59, sohu0106 wrote:

The stack object "kbdiacr" has a total size of 4 bytes. Its last 1 bytes are padding bytes after "result" which are not initialized and leaked to userland via "copy_to_user".

keyboard.c +0 -0
index ba0e4f9..76a6d35 100644

keyboard.c int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) · line 484

Quoted 5 lines
keyboard.c +2 -0
@@ -480,6 +480,8 @@ int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg)
                struct kbdiacr diacr;
                int i;
 
+               memset( &diacr, 0, sizeof(struct kbdiacr) );
+

I think it would be nicer to simply init the struct with "= {}" directly, i.e.:

		struct kbdiacr diacr = {};

And by the way, please have a look at the kernel patch submission guidelines first, especially the COO part here:

https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

So looking at your patch, please try to send plain text mails, and sign your patch with a Signed-off-by line (i.e. no anonymous contributions).

Thanks!
Thomas

#2 lore raw
Quoted 21 lines · Thomas Huth

Hi,

Quoted 9 lines · On 03.08.2017 15:59, sohu0106 wrote:

The stack object "kbdiacr" has a total size of 4 bytes. Its last 1 bytes are padding bytes after "result" which are not initialized and leaked to userland via "copy_to_user".

keyboard.c +0 -0
index ba0e4f9..76a6d35 100644

keyboard.c int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) · line 484

Quoted 5 lines
keyboard.c +2 -0
@@ -480,6 +480,8 @@ int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg)
                struct kbdiacr diacr;
                int i;
 
+               memset( &diacr, 0, sizeof(struct kbdiacr) );
+

I think it would be nicer to simply init the struct with "= {}" directly, i.e.:

Quoted 4 lines
		struct kbdiacr diacr = {};

And by the way, please have a look at the kernel patch submission guidelines first, especially the COO part here:

The patch doesn't make sense. There is no padding and therefore no information leak.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 15 lines · On 05.08.2017 03:57, sohu0106 wrote:

My idea is

struct kbdiacr {
        unsigned char diacr, base, result;
};

sizeof(struct kbdiacr)=4

here we just set 3 bytes
case KDGKBDIACR:
{
struct kbdiacrs __user *a = argp;
struct kbdiacr diacr;
int i;

Quoted 8 lines

if (put_user(kbd->accent_table_size, &a->kb_cnt)) return -EFAULT;
for (i = 0; i < kbd->accent_table_size; i++) { diacr.diacr = kbd->accent_table[i].diacr;
diacr.base = kbd->accent_table[i].base;
diacr.result = kbd->accent_table[i].result;
if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) Is there anything I haven't noticed?

Yes: sizeof(struct kbdiacr) is 3 here.

Thomas