All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit
@ 2019-04-30 12:16 Oliver Neukum
  2019-04-30 12:32 ` Mauro Carvalho Chehab
  2019-05-03  5:10 ` kbuild test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Oliver Neukum @ 2019-04-30 12:16 UTC (permalink / raw)
  To: mchehab, linux-media; +Cc: Oliver Neukum

dvb_usb_device_exit() frees and uses the device name in that order
Fix by storing the name in a buffer before freeing it

v2: fixed style issues
v3: strscpy used and variable names changed

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Reported-by: syzbot+26ec41e9f788b3eba396@syzkaller.appspotmail.com
---
 drivers/media/usb/dvb-usb/dvb-usb-init.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
index 99951e02a880..48d17736db5d 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
@@ -287,12 +287,15 @@ EXPORT_SYMBOL(dvb_usb_device_init);
 void dvb_usb_device_exit(struct usb_interface *intf)
 {
 	struct dvb_usb_device *d = usb_get_intfdata(intf);
-	const char *name = "generic DVB-USB module";
+	const char *default_name = "generic DVB-USB module";
+	char name[40];
 
 	usb_set_intfdata(intf, NULL);
 	if (d != NULL && d->desc != NULL) {
-		name = d->desc->name;
+		strscpy(name, d->desc->name, sizeof(name));
 		dvb_usb_exit(d);
+	} else {
+		memcpy(name, default_name, sizeof(name));
 	}
 	info("%s successfully deinitialized and disconnected.", name);
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit
  2019-04-30 12:16 [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit Oliver Neukum
@ 2019-04-30 12:32 ` Mauro Carvalho Chehab
  2019-05-03  5:10 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2019-04-30 12:32 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-media

Em Tue, 30 Apr 2019 14:16:07 +0200
Oliver Neukum <oneukum@suse.com> escreveu:

> dvb_usb_device_exit() frees and uses the device name in that order
> Fix by storing the name in a buffer before freeing it
> 
> v2: fixed style issues
> v3: strscpy used and variable names changed
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> Reported-by: syzbot+26ec41e9f788b3eba396@syzkaller.appspotmail.com
> ---
>  drivers/media/usb/dvb-usb/dvb-usb-init.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
> index 99951e02a880..48d17736db5d 100644
> --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
> +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
> @@ -287,12 +287,15 @@ EXPORT_SYMBOL(dvb_usb_device_init);
>  void dvb_usb_device_exit(struct usb_interface *intf)
>  {
>  	struct dvb_usb_device *d = usb_get_intfdata(intf);
> -	const char *name = "generic DVB-USB module";
> +	const char *default_name = "generic DVB-USB module";
> +	char name[40];
>  
>  	usb_set_intfdata(intf, NULL);
>  	if (d != NULL && d->desc != NULL) {
> -		name = d->desc->name;
> +		strscpy(name, d->desc->name, sizeof(name));
>  		dvb_usb_exit(d);
> +	} else {
> +		memcpy(name, default_name, sizeof(name));

Please use strscpy() here too, as we're using it everywhere 
when a string requires copy inside media.

>  	}
>  	info("%s successfully deinitialized and disconnected.", name);
>  



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit
  2019-04-30 12:16 [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit Oliver Neukum
  2019-04-30 12:32 ` Mauro Carvalho Chehab
@ 2019-05-03  5:10 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2019-05-03  5:10 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: kbuild-all, mchehab, linux-media, Oliver Neukum

[-- Attachment #1: Type: text/plain, Size: 7759 bytes --]

Hi Oliver,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.1-rc7 next-20190502]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Oliver-Neukum/dvb-usb-fix-use-after-free-in-dvb_usb_device_exit/20190503-112248
base:   git://linuxtv.org/media_tree.git master
config: i386-randconfig-x003-201917 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   Cyclomatic Complexity 1 arch/x86/include/asm/bitops.h:fls
   Cyclomatic Complexity 1 include/linux/log2.h:__ilog2_u32
   Cyclomatic Complexity 4 include/linux/string.h:memcpy
   Cyclomatic Complexity 1 include/asm-generic/getorder.h:__get_order
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/usb.h:usb_get_intfdata
   Cyclomatic Complexity 1 include/linux/usb.h:usb_set_intfdata
   Cyclomatic Complexity 1 include/linux/usb.h:interface_to_usbdev
   Cyclomatic Complexity 1 include/linux/usb.h:__create_pipe
   Cyclomatic Complexity 3 include/linux/slab.h:kmalloc_type
   Cyclomatic Complexity 28 include/linux/slab.h:kmalloc_index
   Cyclomatic Complexity 67 include/linux/slab.h:kmalloc_large
   Cyclomatic Complexity 4 include/linux/slab.h:kmalloc
   Cyclomatic Complexity 1 include/linux/slab.h:kzalloc
   Cyclomatic Complexity 15 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_find_device
   Cyclomatic Complexity 20 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_adapter_init
   Cyclomatic Complexity 2 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_adapter_exit
   Cyclomatic Complexity 3 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_exit
   Cyclomatic Complexity 3 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_exit
   Cyclomatic Complexity 7 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_power_ctrl
   Cyclomatic Complexity 6 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_init
   Cyclomatic Complexity 10 drivers/media/usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_init
   In file included from arch/x86/include/asm/page_32.h:35:0,
                    from arch/x86/include/asm/page.h:14,
                    from arch/x86/include/asm/thread_info.h:12,
                    from include/linux/thread_info.h:38,
                    from arch/x86/include/asm/preempt.h:7,
                    from include/linux/preempt.h:78,
                    from include/linux/spinlock.h:51,
                    from include/linux/seqlock.h:36,
                    from include/linux/time.h:6,
                    from include/linux/input.h:11,
                    from drivers/media/usb/dvb-usb/dvb-usb.h:14,
                    from drivers/media/usb/dvb-usb/dvb-usb-common.h:13,
                    from drivers/media/usb/dvb-usb/dvb-usb-init.c:14:
   In function 'memcpy',
       inlined from 'dvb_usb_device_exit' at drivers/media/usb/dvb-usb/dvb-usb-init.c:298:3:
>> include/linux/string.h:348:4: error: call to '__read_overflow2' declared with attribute error: detected read beyond size of object passed as 2nd parameter
       __read_overflow2();
       ^~~~~~~~~~~~~~~~~~
--
   Cyclomatic Complexity 1 arch/x86/include/asm/bitops.h:fls
   Cyclomatic Complexity 1 include/linux/log2.h:__ilog2_u32
   Cyclomatic Complexity 4 include/linux/string.h:memcpy
   Cyclomatic Complexity 1 include/asm-generic/getorder.h:__get_order
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/usb.h:usb_get_intfdata
   Cyclomatic Complexity 1 include/linux/usb.h:usb_set_intfdata
   Cyclomatic Complexity 1 include/linux/usb.h:interface_to_usbdev
   Cyclomatic Complexity 1 include/linux/usb.h:__create_pipe
   Cyclomatic Complexity 3 include/linux/slab.h:kmalloc_type
   Cyclomatic Complexity 28 include/linux/slab.h:kmalloc_index
   Cyclomatic Complexity 67 include/linux/slab.h:kmalloc_large
   Cyclomatic Complexity 4 include/linux/slab.h:kmalloc
   Cyclomatic Complexity 1 include/linux/slab.h:kzalloc
   Cyclomatic Complexity 15 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_find_device
   Cyclomatic Complexity 20 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_adapter_init
   Cyclomatic Complexity 2 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_adapter_exit
   Cyclomatic Complexity 3 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_exit
   Cyclomatic Complexity 3 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_exit
   Cyclomatic Complexity 7 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_power_ctrl
   Cyclomatic Complexity 6 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_init
   Cyclomatic Complexity 10 drivers/media//usb/dvb-usb/dvb-usb-init.c:dvb_usb_device_init
   In file included from arch/x86/include/asm/page_32.h:35:0,
                    from arch/x86/include/asm/page.h:14,
                    from arch/x86/include/asm/thread_info.h:12,
                    from include/linux/thread_info.h:38,
                    from arch/x86/include/asm/preempt.h:7,
                    from include/linux/preempt.h:78,
                    from include/linux/spinlock.h:51,
                    from include/linux/seqlock.h:36,
                    from include/linux/time.h:6,
                    from include/linux/input.h:11,
                    from drivers/media//usb/dvb-usb/dvb-usb.h:14,
                    from drivers/media//usb/dvb-usb/dvb-usb-common.h:13,
                    from drivers/media//usb/dvb-usb/dvb-usb-init.c:14:
   In function 'memcpy',
       inlined from 'dvb_usb_device_exit' at drivers/media//usb/dvb-usb/dvb-usb-init.c:298:3:
>> include/linux/string.h:348:4: error: call to '__read_overflow2' declared with attribute error: detected read beyond size of object passed as 2nd parameter
       __read_overflow2();
       ^~~~~~~~~~~~~~~~~~

vim +/__read_overflow2 +348 include/linux/string.h

6974f0c4 Daniel Micay 2017-07-12  339  
6974f0c4 Daniel Micay 2017-07-12  340  __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
6974f0c4 Daniel Micay 2017-07-12  341  {
6974f0c4 Daniel Micay 2017-07-12  342  	size_t p_size = __builtin_object_size(p, 0);
6974f0c4 Daniel Micay 2017-07-12  343  	size_t q_size = __builtin_object_size(q, 0);
6974f0c4 Daniel Micay 2017-07-12  344  	if (__builtin_constant_p(size)) {
6974f0c4 Daniel Micay 2017-07-12  345  		if (p_size < size)
6974f0c4 Daniel Micay 2017-07-12  346  			__write_overflow();
6974f0c4 Daniel Micay 2017-07-12  347  		if (q_size < size)
6974f0c4 Daniel Micay 2017-07-12 @348  			__read_overflow2();
6974f0c4 Daniel Micay 2017-07-12  349  	}
6974f0c4 Daniel Micay 2017-07-12  350  	if (p_size < size || q_size < size)
6974f0c4 Daniel Micay 2017-07-12  351  		fortify_panic(__func__);
6974f0c4 Daniel Micay 2017-07-12  352  	return __builtin_memcpy(p, q, size);
6974f0c4 Daniel Micay 2017-07-12  353  }
6974f0c4 Daniel Micay 2017-07-12  354  

:::::: The code at line 348 was first introduced by commit
:::::: 6974f0c4555e285ab217cee58b6e874f776ff409 include/linux/string.h: add the option of fortified string.h functions

:::::: TO: Daniel Micay <danielmicay@gmail.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33145 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-03  5:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30 12:16 [PATCHv3] dvb: usb: fix use after free in dvb_usb_device_exit Oliver Neukum
2019-04-30 12:32 ` Mauro Carvalho Chehab
2019-05-03  5:10 ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.