lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <202211291340.68PzvPjV-lkp@intel.com>
Date:   Tue, 29 Nov 2022 13:26:34 +0800
From:   kernel test robot <lkp@...el.com>
To:     Bartosz Golaszewski <brgl@...ev.pl>,
        Kent Gibson <warthog618@...il.com>,
        Linus Walleij <linus.walleij@...aro.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:     oe-kbuild-all@...ts.linux.dev, linux-gpio@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v2 2/2] gpiolib: protect the GPIO device against being
 dropped while in use by user-space

Hi Bartosz,

I love your patch! Yet something to improve:

[auto build test ERROR on brgl/gpio/for-next]
[also build test ERROR on linus/master v6.1-rc7 next-20221128]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpiolib-don-t-allow-user-space-to-crash-the-kernel-with-hot-unplugs/20221129-021037
base:   https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
patch link:    https://lore.kernel.org/r/20221128175214.602612-3-brgl%40bgdev.pl
patch subject: [PATCH v2 2/2] gpiolib: protect the GPIO device against being dropped while in use by user-space
config: arm-randconfig-r046-20221128
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/ccf2821b643c23a5ef6fac8a4785c2127d4125c7
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Bartosz-Golaszewski/gpiolib-don-t-allow-user-space-to-crash-the-kernel-with-hot-unplugs/20221129-021037
        git checkout ccf2821b643c23a5ef6fac8a4785c2127d4125c7
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/gpio/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>

All error/warnings (new ones prefixed by >>):

   drivers/gpio/gpiolib-cdev.c: In function 'lineinfo_watch_read':
>> drivers/gpio/gpiolib-cdev.c:2647:1: error: expected 'while' before 'static'
    2647 | static int gpio_chrdev_open(struct inode *inode, struct file *file)
         | ^~~~~~
>> drivers/gpio/gpiolib-cdev.c:2709:12: error: invalid storage class for function 'gpio_chrdev_release'
    2709 | static int gpio_chrdev_release(struct inode *inode, struct file *file)
         |            ^~~~~~~~~~~~~~~~~~~
>> drivers/gpio/gpiolib-cdev.c:2709:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    2709 | static int gpio_chrdev_release(struct inode *inode, struct file *file)
         | ^~~~~~
>> drivers/gpio/gpiolib-cdev.c:2724:20: error: initializer element is not constant
    2724 |         .release = gpio_chrdev_release,
         |                    ^~~~~~~~~~~~~~~~~~~
   drivers/gpio/gpiolib-cdev.c:2724:20: note: (near initialization for 'gpio_fileops.release')
>> drivers/gpio/gpiolib-cdev.c:2725:17: error: 'gpio_chrdev_open' undeclared (first use in this function); did you mean 'gpio_chardev_data'?
    2725 |         .open = gpio_chrdev_open,
         |                 ^~~~~~~~~~~~~~~~
         |                 gpio_chardev_data
   drivers/gpio/gpiolib-cdev.c:2725:17: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/gpio/gpiolib-cdev.c:2757:1: error: expected declaration or statement at end of input
    2757 | }
         | ^
   drivers/gpio/gpiolib-cdev.c: At top level:
   drivers/gpio/gpiolib-cdev.c:2754:6: warning: 'gpiolib_cdev_unregister' defined but not used [-Wunused-function]
    2754 | void gpiolib_cdev_unregister(struct gpio_device *gdev)
         |      ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpio/gpiolib-cdev.c:2736:5: warning: 'gpiolib_cdev_register' defined but not used [-Wunused-function]
    2736 | int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
         |     ^~~~~~~~~~~~~~~~~~~~~
   drivers/gpio/gpiolib-cdev.c:2543:16: warning: 'lineinfo_watch_read' defined but not used [-Wunused-function]
    2543 | static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
         |                ^~~~~~~~~~~~~~~~~~~
   drivers/gpio/gpiolib-cdev.c:2494:12: warning: 'lineinfo_changed_notify' defined but not used [-Wunused-function]
    2494 | static int lineinfo_changed_notify(struct notifier_block *nb,
         |            ^~~~~~~~~~~~~~~~~~~~~~~


vim +2647 drivers/gpio/gpiolib-cdev.c

925ca36913fc7df Kent Gibson         2020-06-16  2640  
925ca36913fc7df Kent Gibson         2020-06-16  2641  /**
925ca36913fc7df Kent Gibson         2020-06-16  2642   * gpio_chrdev_open() - open the chardev for ioctl operations
925ca36913fc7df Kent Gibson         2020-06-16  2643   * @inode: inode for this chardev
49bc52798d7bb66 Kent Gibson         2020-07-08  2644   * @file: file struct for storing private data
925ca36913fc7df Kent Gibson         2020-06-16  2645   * Returns 0 on success
925ca36913fc7df Kent Gibson         2020-06-16  2646   */
49bc52798d7bb66 Kent Gibson         2020-07-08 @2647  static int gpio_chrdev_open(struct inode *inode, struct file *file)
925ca36913fc7df Kent Gibson         2020-06-16  2648  {
925ca36913fc7df Kent Gibson         2020-06-16  2649  	struct gpio_device *gdev = container_of(inode->i_cdev,
925ca36913fc7df Kent Gibson         2020-06-16  2650  						struct gpio_device, chrdev);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2651  	struct gpio_chardev_data *cdev;
925ca36913fc7df Kent Gibson         2020-06-16  2652  	int ret = -ENOMEM;
925ca36913fc7df Kent Gibson         2020-06-16  2653  
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2654  	down_read(&gdev->sem);
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2655  
925ca36913fc7df Kent Gibson         2020-06-16  2656  	/* Fail on open if the backing gpiochip is gone */
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2657  	if (!gdev->chip) {
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2658  		up_read(&gdev->sem);
925ca36913fc7df Kent Gibson         2020-06-16  2659  		return -ENODEV;
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2660  	}
925ca36913fc7df Kent Gibson         2020-06-16  2661  
e2b781c5f0dd45f Kent Gibson         2020-07-08  2662  	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2663  	if (!cdev) {
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2664  		up_read(&gdev->sem);
925ca36913fc7df Kent Gibson         2020-06-16  2665  		return -ENOMEM;
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2666  	}
925ca36913fc7df Kent Gibson         2020-06-16  2667  
e2b781c5f0dd45f Kent Gibson         2020-07-08  2668  	cdev->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2669  	if (!cdev->watched_lines)
e2b781c5f0dd45f Kent Gibson         2020-07-08  2670  		goto out_free_cdev;
925ca36913fc7df Kent Gibson         2020-06-16  2671  
e2b781c5f0dd45f Kent Gibson         2020-07-08  2672  	init_waitqueue_head(&cdev->wait);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2673  	INIT_KFIFO(cdev->events);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2674  	cdev->gdev = gdev;
925ca36913fc7df Kent Gibson         2020-06-16  2675  
e2b781c5f0dd45f Kent Gibson         2020-07-08  2676  	cdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify;
6accc376a7482ec Kent Gibson         2020-07-08  2677  	ret = blocking_notifier_chain_register(&gdev->notifier,
e2b781c5f0dd45f Kent Gibson         2020-07-08  2678  					       &cdev->lineinfo_changed_nb);
925ca36913fc7df Kent Gibson         2020-06-16  2679  	if (ret)
925ca36913fc7df Kent Gibson         2020-06-16  2680  		goto out_free_bitmap;
925ca36913fc7df Kent Gibson         2020-06-16  2681  
925ca36913fc7df Kent Gibson         2020-06-16  2682  	get_device(&gdev->dev);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2683  	file->private_data = cdev;
925ca36913fc7df Kent Gibson         2020-06-16  2684  
49bc52798d7bb66 Kent Gibson         2020-07-08  2685  	ret = nonseekable_open(inode, file);
925ca36913fc7df Kent Gibson         2020-06-16  2686  	if (ret)
925ca36913fc7df Kent Gibson         2020-06-16  2687  		goto out_unregister_notifier;
925ca36913fc7df Kent Gibson         2020-06-16  2688  
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2689  	up_read(&gdev->sem);
925ca36913fc7df Kent Gibson         2020-06-16  2690  	return ret;
925ca36913fc7df Kent Gibson         2020-06-16  2691  
925ca36913fc7df Kent Gibson         2020-06-16  2692  out_unregister_notifier:
6accc376a7482ec Kent Gibson         2020-07-08  2693  	blocking_notifier_chain_unregister(&gdev->notifier,
e2b781c5f0dd45f Kent Gibson         2020-07-08  2694  					   &cdev->lineinfo_changed_nb);
925ca36913fc7df Kent Gibson         2020-06-16  2695  out_free_bitmap:
e2b781c5f0dd45f Kent Gibson         2020-07-08  2696  	bitmap_free(cdev->watched_lines);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2697  out_free_cdev:
e2b781c5f0dd45f Kent Gibson         2020-07-08  2698  	kfree(cdev);
ccf2821b643c23a Bartosz Golaszewski 2022-11-28  2699  	up_read(&gdev->sem);
925ca36913fc7df Kent Gibson         2020-06-16  2700  	return ret;
925ca36913fc7df Kent Gibson         2020-06-16  2701  }
925ca36913fc7df Kent Gibson         2020-06-16  2702  
925ca36913fc7df Kent Gibson         2020-06-16  2703  /**
925ca36913fc7df Kent Gibson         2020-06-16  2704   * gpio_chrdev_release() - close chardev after ioctl operations
925ca36913fc7df Kent Gibson         2020-06-16  2705   * @inode: inode for this chardev
49bc52798d7bb66 Kent Gibson         2020-07-08  2706   * @file: file struct for storing private data
925ca36913fc7df Kent Gibson         2020-06-16  2707   * Returns 0 on success
925ca36913fc7df Kent Gibson         2020-06-16  2708   */
49bc52798d7bb66 Kent Gibson         2020-07-08 @2709  static int gpio_chrdev_release(struct inode *inode, struct file *file)
925ca36913fc7df Kent Gibson         2020-06-16  2710  {
e2b781c5f0dd45f Kent Gibson         2020-07-08  2711  	struct gpio_chardev_data *cdev = file->private_data;
e2b781c5f0dd45f Kent Gibson         2020-07-08  2712  	struct gpio_device *gdev = cdev->gdev;
925ca36913fc7df Kent Gibson         2020-06-16  2713  
e2b781c5f0dd45f Kent Gibson         2020-07-08  2714  	bitmap_free(cdev->watched_lines);
6accc376a7482ec Kent Gibson         2020-07-08  2715  	blocking_notifier_chain_unregister(&gdev->notifier,
e2b781c5f0dd45f Kent Gibson         2020-07-08  2716  					   &cdev->lineinfo_changed_nb);
925ca36913fc7df Kent Gibson         2020-06-16  2717  	put_device(&gdev->dev);
e2b781c5f0dd45f Kent Gibson         2020-07-08  2718  	kfree(cdev);
925ca36913fc7df Kent Gibson         2020-06-16  2719  
925ca36913fc7df Kent Gibson         2020-06-16  2720  	return 0;
925ca36913fc7df Kent Gibson         2020-06-16  2721  }
925ca36913fc7df Kent Gibson         2020-06-16  2722  
925ca36913fc7df Kent Gibson         2020-06-16  2723  static const struct file_operations gpio_fileops = {
925ca36913fc7df Kent Gibson         2020-06-16 @2724  	.release = gpio_chrdev_release,
925ca36913fc7df Kent Gibson         2020-06-16 @2725  	.open = gpio_chrdev_open,
925ca36913fc7df Kent Gibson         2020-06-16  2726  	.poll = lineinfo_watch_poll,
925ca36913fc7df Kent Gibson         2020-06-16  2727  	.read = lineinfo_watch_read,
925ca36913fc7df Kent Gibson         2020-06-16  2728  	.owner = THIS_MODULE,
925ca36913fc7df Kent Gibson         2020-06-16  2729  	.llseek = no_llseek,
925ca36913fc7df Kent Gibson         2020-06-16  2730  	.unlocked_ioctl = gpio_ioctl,
925ca36913fc7df Kent Gibson         2020-06-16  2731  #ifdef CONFIG_COMPAT
925ca36913fc7df Kent Gibson         2020-06-16  2732  	.compat_ioctl = gpio_ioctl_compat,
925ca36913fc7df Kent Gibson         2020-06-16  2733  #endif
925ca36913fc7df Kent Gibson         2020-06-16  2734  };
925ca36913fc7df Kent Gibson         2020-06-16  2735  
925ca36913fc7df Kent Gibson         2020-06-16  2736  int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
925ca36913fc7df Kent Gibson         2020-06-16  2737  {
925ca36913fc7df Kent Gibson         2020-06-16  2738  	int ret;
925ca36913fc7df Kent Gibson         2020-06-16  2739  
925ca36913fc7df Kent Gibson         2020-06-16  2740  	cdev_init(&gdev->chrdev, &gpio_fileops);
925ca36913fc7df Kent Gibson         2020-06-16  2741  	gdev->chrdev.owner = THIS_MODULE;
925ca36913fc7df Kent Gibson         2020-06-16  2742  	gdev->dev.devt = MKDEV(MAJOR(devt), gdev->id);
925ca36913fc7df Kent Gibson         2020-06-16  2743  
925ca36913fc7df Kent Gibson         2020-06-16  2744  	ret = cdev_device_add(&gdev->chrdev, &gdev->dev);
925ca36913fc7df Kent Gibson         2020-06-16  2745  	if (ret)
925ca36913fc7df Kent Gibson         2020-06-16  2746  		return ret;
925ca36913fc7df Kent Gibson         2020-06-16  2747  
925ca36913fc7df Kent Gibson         2020-06-16  2748  	chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n",
925ca36913fc7df Kent Gibson         2020-06-16  2749  		 MAJOR(devt), gdev->id);
925ca36913fc7df Kent Gibson         2020-06-16  2750  
925ca36913fc7df Kent Gibson         2020-06-16  2751  	return 0;
925ca36913fc7df Kent Gibson         2020-06-16  2752  }
925ca36913fc7df Kent Gibson         2020-06-16  2753  
925ca36913fc7df Kent Gibson         2020-06-16  2754  void gpiolib_cdev_unregister(struct gpio_device *gdev)
925ca36913fc7df Kent Gibson         2020-06-16  2755  {
925ca36913fc7df Kent Gibson         2020-06-16  2756  	cdev_device_del(&gdev->chrdev, &gdev->dev);
925ca36913fc7df Kent Gibson         2020-06-16 @2757  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

View attachment "config" of type "text/plain" (173827 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ