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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190107185824.GD3253@kadam>
Date:   Mon, 7 Jan 2019 21:58:24 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     kbuild@...org, "Lee, Chun-Yi" <joeyli.kernel@...il.com>
Cc:     kbuild-all@...org, "Rafael J . Wysocki" <rjw@...ysocki.net>,
        Pavel Machek <pavel@....cz>, linux-kernel@...r.kernel.org,
        linux-pm@...r.kernel.org, keyrings@...r.kernel.org,
        "Lee, Chun-Yi" <jlee@...e.com>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        Chen Yu <yu.c.chen@...el.com>,
        Oliver Neukum <oneukum@...e.com>,
        Ryan Chen <yu.chen.surf@...il.com>,
        David Howells <dhowells@...hat.com>,
        Giovanni Gherdovich <ggherdovich@...e.cz>,
        Randy Dunlap <rdunlap@...radead.org>,
        Jann Horn <jannh@...gle.com>, Andy Lutomirski <luto@...nel.org>
Subject: Re: [PATCH 2/5] PM / hibernate: Generate and verify signature for
 snapshot image

Hi Chun-Yi,

url:    https://github.com/0day-ci/linux/commits/Lee-Chun-Yi/Encryption-and-authentication-for-hibernate-snapshot-image/20190104-062004

smatch warnings:
kernel/power/user.c:411 snapshot_ioctl() warn: inconsistent returns 'mutex:&system_transition_mutex'.
  Locked on:   line 265
  Unlocked on: line 213

[ There are some returns missing.  I don't know how/why...  -dan ]

# https://github.com/0day-ci/linux/commit/1e583ff7a095d508d78bea4d35a916594c2fc23c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 1e583ff7a095d508d78bea4d35a916594c2fc23c
vim +411 kernel/power/user.c

6e1819d61 Rafael J. Wysocki 2006-03-23  203  
52d11025d Alan Cox          2008-06-11  204  static long snapshot_ioctl(struct file *filp, unsigned int cmd,
52d11025d Alan Cox          2008-06-11  205  							unsigned long arg)
6e1819d61 Rafael J. Wysocki 2006-03-23  206  {
6e1819d61 Rafael J. Wysocki 2006-03-23  207  	int error = 0;
6e1819d61 Rafael J. Wysocki 2006-03-23  208  	struct snapshot_data *data;
af508b34d Rafael J. Wysocki 2007-10-26  209  	loff_t size;
3aef83e0e Rafael J. Wysocki 2006-12-06  210  	sector_t offset;
6e1819d61 Rafael J. Wysocki 2006-03-23  211  
6e1819d61 Rafael J. Wysocki 2006-03-23  212  	if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC)
6e1819d61 Rafael J. Wysocki 2006-03-23  213  		return -ENOTTY;
6e1819d61 Rafael J. Wysocki 2006-03-23  214  	if (_IOC_NR(cmd) > SNAPSHOT_IOC_MAXNR)
6e1819d61 Rafael J. Wysocki 2006-03-23  215  		return -ENOTTY;
6e1819d61 Rafael J. Wysocki 2006-03-23  216  	if (!capable(CAP_SYS_ADMIN))
6e1819d61 Rafael J. Wysocki 2006-03-23  217  		return -EPERM;
6e1819d61 Rafael J. Wysocki 2006-03-23  218  
55f2503c3 Pingfan Liu       2018-07-31  219  	if (!mutex_trylock(&system_transition_mutex))
25f2f3daa Rafael J. Wysocki 2008-06-11  220  		return -EBUSY;
6e1819d61 Rafael J. Wysocki 2006-03-23  221  
942f40155 Rafael J. Wysocki 2013-08-30  222  	lock_device_hotplug();
25f2f3daa Rafael J. Wysocki 2008-06-11  223  	data = filp->private_data;
52d11025d Alan Cox          2008-06-11  224  
6e1819d61 Rafael J. Wysocki 2006-03-23  225  	switch (cmd) {
6e1819d61 Rafael J. Wysocki 2006-03-23  226  
6e1819d61 Rafael J. Wysocki 2006-03-23  227  	case SNAPSHOT_FREEZE:
6e1819d61 Rafael J. Wysocki 2006-03-23  228  		if (data->frozen)
6e1819d61 Rafael J. Wysocki 2006-03-23  229  			break;
1bfcf1304 Rafael J. Wysocki 2008-10-15  230  
232b14328 Rafael J. Wysocki 2007-10-18  231  		printk("Syncing filesystems ... ");
70f68ee81 Dominik Brodowski 2018-03-14  232  		ksys_sync();
232b14328 Rafael J. Wysocki 2007-10-18  233  		printk("done.\n");
232b14328 Rafael J. Wysocki 2007-10-18  234  
1bfcf1304 Rafael J. Wysocki 2008-10-15  235  		error = freeze_processes();
8fd37a4c9 Rafael J. Wysocki 2013-08-30  236  		if (error)
8fd37a4c9 Rafael J. Wysocki 2013-08-30  237  			break;
8fd37a4c9 Rafael J. Wysocki 2013-08-30  238  
8fd37a4c9 Rafael J. Wysocki 2013-08-30  239  		error = create_basic_memory_bitmaps();
8fd37a4c9 Rafael J. Wysocki 2013-08-30  240  		if (error)
8fd37a4c9 Rafael J. Wysocki 2013-08-30  241  			thaw_processes();
8fd37a4c9 Rafael J. Wysocki 2013-08-30  242  		else
7bc9b1cff Rafael J. Wysocki 2013-10-18  243  			data->frozen = true;
8fd37a4c9 Rafael J. Wysocki 2013-08-30  244  
6e1819d61 Rafael J. Wysocki 2006-03-23  245  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  246  
6e1819d61 Rafael J. Wysocki 2006-03-23  247  	case SNAPSHOT_UNFREEZE:
2f41dddbb Rafael J. Wysocki 2007-06-16  248  		if (!data->frozen || data->ready)
6e1819d61 Rafael J. Wysocki 2006-03-23  249  			break;
c9e664f1f Rafael J. Wysocki 2010-12-03  250  		pm_restore_gfp_mask();
1e583ff7a Lee, Chun-Yi      2019-01-03  251  		snapshot_restore_trampoline();
8fd37a4c9 Rafael J. Wysocki 2013-08-30  252  		free_basic_memory_bitmaps();
aab172891 Rafael J. Wysocki 2013-09-30  253  		data->free_bitmaps = false;
6e1819d61 Rafael J. Wysocki 2006-03-23  254  		thaw_processes();
7bc9b1cff Rafael J. Wysocki 2013-10-18  255  		data->frozen = false;
6e1819d61 Rafael J. Wysocki 2006-03-23  256  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  257  
b694e52eb Jiri Slaby        2010-01-27  258  	case SNAPSHOT_CREATE_IMAGE:
6e1819d61 Rafael J. Wysocki 2006-03-23  259  		if (data->mode != O_RDONLY || !data->frozen  || data->ready) {
6e1819d61 Rafael J. Wysocki 2006-03-23  260  			error = -EPERM;
6e1819d61 Rafael J. Wysocki 2006-03-23  261  			break;
6e1819d61 Rafael J. Wysocki 2006-03-23  262  		}
1e583ff7a Lee, Chun-Yi      2019-01-03  263  		error = snapshot_key_init();
1e583ff7a Lee, Chun-Yi      2019-01-03  264  		if (error)
1e583ff7a Lee, Chun-Yi      2019-01-03  265  			return error;
                                                                ^^^^^^^^^^^^^

1e583ff7a Lee, Chun-Yi      2019-01-03  266  		error = snapshot_create_trampoline();
1e583ff7a Lee, Chun-Yi      2019-01-03  267  		if (error)
1e583ff7a Lee, Chun-Yi      2019-01-03  268  			return error;
                                                                ^^^^^^^^^^^^^
These should be break statements.

c9e664f1f Rafael J. Wysocki 2010-12-03  269  		pm_restore_gfp_mask();
eb57c1cf0 Rafael J. Wysocki 2007-10-26  270  		error = hibernation_snapshot(data->platform_support);
51d6ff7ac Srivatsa S. Bhat  2012-02-04  271  		if (!error) {
cc5d207c8 Rafael J. Wysocki 2007-10-26  272  			error = put_user(in_suspend, (int __user *)arg);
a556d5b58 Srivatsa S. Bhat  2012-02-04  273  			data->ready = !freezer_test_done && !error;
97819a262 Srivatsa S. Bhat  2011-12-01  274  			freezer_test_done = false;
97819a262 Srivatsa S. Bhat  2011-12-01  275  		}
6e1819d61 Rafael J. Wysocki 2006-03-23  276  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  277  
6e1819d61 Rafael J. Wysocki 2006-03-23  278  	case SNAPSHOT_ATOMIC_RESTORE:
8357376d3 Rafael J. Wysocki 2006-12-06  279  		snapshot_write_finalize(&data->handle);
6e1819d61 Rafael J. Wysocki 2006-03-23  280  		if (data->mode != O_WRONLY || !data->frozen ||
6e1819d61 Rafael J. Wysocki 2006-03-23  281  		    !snapshot_image_loaded(&data->handle)) {
6e1819d61 Rafael J. Wysocki 2006-03-23  282  			error = -EPERM;
6e1819d61 Rafael J. Wysocki 2006-03-23  283  			break;
6e1819d61 Rafael J. Wysocki 2006-03-23  284  		}
1e583ff7a Lee, Chun-Yi      2019-01-03  285  		if (snapshot_image_verify_decrypt()) {
1e583ff7a Lee, Chun-Yi      2019-01-03  286  			error = -EPERM;
1e583ff7a Lee, Chun-Yi      2019-01-03  287  			break;
1e583ff7a Lee, Chun-Yi      2019-01-03  288  		}
1e583ff7a Lee, Chun-Yi      2019-01-03  289  		snapshot_init_trampoline();
eb57c1cf0 Rafael J. Wysocki 2007-10-26  290  		error = hibernation_restore(data->platform_support);
6e1819d61 Rafael J. Wysocki 2006-03-23  291  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  292  
6e1819d61 Rafael J. Wysocki 2006-03-23  293  	case SNAPSHOT_FREE:
6e1819d61 Rafael J. Wysocki 2006-03-23  294  		swsusp_free();
6e1819d61 Rafael J. Wysocki 2006-03-23  295  		memset(&data->handle, 0, sizeof(struct snapshot_handle));
7bc9b1cff Rafael J. Wysocki 2013-10-18  296  		data->ready = false;
181e9bdef Rafael J. Wysocki 2012-01-29  297  		/*
181e9bdef Rafael J. Wysocki 2012-01-29  298  		 * It is necessary to thaw kernel threads here, because
181e9bdef Rafael J. Wysocki 2012-01-29  299  		 * SNAPSHOT_CREATE_IMAGE may be invoked directly after
181e9bdef Rafael J. Wysocki 2012-01-29  300  		 * SNAPSHOT_FREE.  In that case, if kernel threads were not
181e9bdef Rafael J. Wysocki 2012-01-29  301  		 * thawed, the preallocation of memory carried out by
181e9bdef Rafael J. Wysocki 2012-01-29  302  		 * hibernation_snapshot() might run into problems (i.e. it
181e9bdef Rafael J. Wysocki 2012-01-29  303  		 * might fail or even deadlock).
181e9bdef Rafael J. Wysocki 2012-01-29  304  		 */
181e9bdef Rafael J. Wysocki 2012-01-29  305  		thaw_kernel_threads();
6e1819d61 Rafael J. Wysocki 2006-03-23  306  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  307  
b694e52eb Jiri Slaby        2010-01-27  308  	case SNAPSHOT_PREF_IMAGE_SIZE:
6e1819d61 Rafael J. Wysocki 2006-03-23  309  		image_size = arg;
6e1819d61 Rafael J. Wysocki 2006-03-23  310  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  311  
af508b34d Rafael J. Wysocki 2007-10-26  312  	case SNAPSHOT_GET_IMAGE_SIZE:
af508b34d Rafael J. Wysocki 2007-10-26  313  		if (!data->ready) {
af508b34d Rafael J. Wysocki 2007-10-26  314  			error = -ENODATA;
af508b34d Rafael J. Wysocki 2007-10-26  315  			break;
af508b34d Rafael J. Wysocki 2007-10-26  316  		}
af508b34d Rafael J. Wysocki 2007-10-26  317  		size = snapshot_get_image_size();
af508b34d Rafael J. Wysocki 2007-10-26  318  		size <<= PAGE_SHIFT;
af508b34d Rafael J. Wysocki 2007-10-26  319  		error = put_user(size, (loff_t __user *)arg);
af508b34d Rafael J. Wysocki 2007-10-26  320  		break;
af508b34d Rafael J. Wysocki 2007-10-26  321  
b694e52eb Jiri Slaby        2010-01-27  322  	case SNAPSHOT_AVAIL_SWAP_SIZE:
af508b34d Rafael J. Wysocki 2007-10-26  323  		size = count_swap_pages(data->swap, 1);
af508b34d Rafael J. Wysocki 2007-10-26  324  		size <<= PAGE_SHIFT;
af508b34d Rafael J. Wysocki 2007-10-26  325  		error = put_user(size, (loff_t __user *)arg);
6e1819d61 Rafael J. Wysocki 2006-03-23  326  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  327  
b694e52eb Jiri Slaby        2010-01-27  328  	case SNAPSHOT_ALLOC_SWAP_PAGE:
6e1819d61 Rafael J. Wysocki 2006-03-23  329  		if (data->swap < 0 || data->swap >= MAX_SWAPFILES) {
6e1819d61 Rafael J. Wysocki 2006-03-23  330  			error = -ENODEV;
6e1819d61 Rafael J. Wysocki 2006-03-23  331  			break;
6e1819d61 Rafael J. Wysocki 2006-03-23  332  		}
d1d241cc2 Rafael J. Wysocki 2007-05-06  333  		offset = alloc_swapdev_block(data->swap);
6e1819d61 Rafael J. Wysocki 2006-03-23  334  		if (offset) {
6e1819d61 Rafael J. Wysocki 2006-03-23  335  			offset <<= PAGE_SHIFT;
cc5d207c8 Rafael J. Wysocki 2007-10-26  336  			error = put_user(offset, (loff_t __user *)arg);
6e1819d61 Rafael J. Wysocki 2006-03-23  337  		} else {
6e1819d61 Rafael J. Wysocki 2006-03-23  338  			error = -ENOSPC;
6e1819d61 Rafael J. Wysocki 2006-03-23  339  		}
6e1819d61 Rafael J. Wysocki 2006-03-23  340  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  341  
6e1819d61 Rafael J. Wysocki 2006-03-23  342  	case SNAPSHOT_FREE_SWAP_PAGES:
6e1819d61 Rafael J. Wysocki 2006-03-23  343  		if (data->swap < 0 || data->swap >= MAX_SWAPFILES) {
6e1819d61 Rafael J. Wysocki 2006-03-23  344  			error = -ENODEV;
6e1819d61 Rafael J. Wysocki 2006-03-23  345  			break;
6e1819d61 Rafael J. Wysocki 2006-03-23  346  		}
d1d241cc2 Rafael J. Wysocki 2007-05-06  347  		free_all_swap_pages(data->swap);
6e1819d61 Rafael J. Wysocki 2006-03-23  348  		break;
6e1819d61 Rafael J. Wysocki 2006-03-23  349  
9b238205b Luca Tettamanti   2006-03-23  350  	case SNAPSHOT_S2RAM:
9b238205b Luca Tettamanti   2006-03-23  351  		if (!data->frozen) {
9b238205b Luca Tettamanti   2006-03-23  352  			error = -EPERM;
9b238205b Luca Tettamanti   2006-03-23  353  			break;
9b238205b Luca Tettamanti   2006-03-23  354  		}
6c961dfb7 Rafael J. Wysocki 2007-07-19  355  		/*
6c961dfb7 Rafael J. Wysocki 2007-07-19  356  		 * Tasks are frozen and the notifiers have been called with
6c961dfb7 Rafael J. Wysocki 2007-07-19  357  		 * PM_HIBERNATION_PREPARE
6c961dfb7 Rafael J. Wysocki 2007-07-19  358  		 */
6c961dfb7 Rafael J. Wysocki 2007-07-19  359  		error = suspend_devices_and_enter(PM_SUSPEND_MEM);
7bc9b1cff Rafael J. Wysocki 2013-10-18  360  		data->ready = false;
9b238205b Luca Tettamanti   2006-03-23  361  		break;
9b238205b Luca Tettamanti   2006-03-23  362  
eb57c1cf0 Rafael J. Wysocki 2007-10-26  363  	case SNAPSHOT_PLATFORM_SUPPORT:
eb57c1cf0 Rafael J. Wysocki 2007-10-26  364  		data->platform_support = !!arg;
eb57c1cf0 Rafael J. Wysocki 2007-10-26  365  		break;
eb57c1cf0 Rafael J. Wysocki 2007-10-26  366  
eb57c1cf0 Rafael J. Wysocki 2007-10-26  367  	case SNAPSHOT_POWER_OFF:
eb57c1cf0 Rafael J. Wysocki 2007-10-26  368  		if (data->platform_support)
eb57c1cf0 Rafael J. Wysocki 2007-10-26  369  			error = hibernation_platform_enter();
eb57c1cf0 Rafael J. Wysocki 2007-10-26  370  		break;
eb57c1cf0 Rafael J. Wysocki 2007-10-26  371  
37b2ba12d Rafael J. Wysocki 2006-12-06  372  	case SNAPSHOT_SET_SWAP_AREA:
d1d241cc2 Rafael J. Wysocki 2007-05-06  373  		if (swsusp_swap_in_use()) {
37b2ba12d Rafael J. Wysocki 2006-12-06  374  			error = -EPERM;
37b2ba12d Rafael J. Wysocki 2006-12-06  375  		} else {
37b2ba12d Rafael J. Wysocki 2006-12-06  376  			struct resume_swap_area swap_area;
37b2ba12d Rafael J. Wysocki 2006-12-06  377  			dev_t swdev;
37b2ba12d Rafael J. Wysocki 2006-12-06  378  
37b2ba12d Rafael J. Wysocki 2006-12-06  379  			error = copy_from_user(&swap_area, (void __user *)arg,
37b2ba12d Rafael J. Wysocki 2006-12-06  380  					sizeof(struct resume_swap_area));
37b2ba12d Rafael J. Wysocki 2006-12-06  381  			if (error) {
37b2ba12d Rafael J. Wysocki 2006-12-06  382  				error = -EFAULT;
37b2ba12d Rafael J. Wysocki 2006-12-06  383  				break;
37b2ba12d Rafael J. Wysocki 2006-12-06  384  			}
37b2ba12d Rafael J. Wysocki 2006-12-06  385  
37b2ba12d Rafael J. Wysocki 2006-12-06  386  			/*
37b2ba12d Rafael J. Wysocki 2006-12-06  387  			 * User space encodes device types as two-byte values,
37b2ba12d Rafael J. Wysocki 2006-12-06  388  			 * so we need to recode them
37b2ba12d Rafael J. Wysocki 2006-12-06  389  			 */
d88d4050d Jiri Slaby        2010-04-10  390  			swdev = new_decode_dev(swap_area.dev);
37b2ba12d Rafael J. Wysocki 2006-12-06  391  			if (swdev) {
37b2ba12d Rafael J. Wysocki 2006-12-06  392  				offset = swap_area.offset;
7bf236874 Rafael J. Wysocki 2007-01-05  393  				data->swap = swap_type_of(swdev, offset, NULL);
37b2ba12d Rafael J. Wysocki 2006-12-06  394  				if (data->swap < 0)
37b2ba12d Rafael J. Wysocki 2006-12-06  395  					error = -ENODEV;
37b2ba12d Rafael J. Wysocki 2006-12-06  396  			} else {
37b2ba12d Rafael J. Wysocki 2006-12-06  397  				data->swap = -1;
37b2ba12d Rafael J. Wysocki 2006-12-06  398  				error = -EINVAL;
37b2ba12d Rafael J. Wysocki 2006-12-06  399  			}
37b2ba12d Rafael J. Wysocki 2006-12-06  400  		}
37b2ba12d Rafael J. Wysocki 2006-12-06  401  		break;
37b2ba12d Rafael J. Wysocki 2006-12-06  402  
6e1819d61 Rafael J. Wysocki 2006-03-23  403  	default:
6e1819d61 Rafael J. Wysocki 2006-03-23  404  		error = -ENOTTY;
6e1819d61 Rafael J. Wysocki 2006-03-23  405  
6e1819d61 Rafael J. Wysocki 2006-03-23  406  	}
25f2f3daa Rafael J. Wysocki 2008-06-11  407  
942f40155 Rafael J. Wysocki 2013-08-30  408  	unlock_device_hotplug();
55f2503c3 Pingfan Liu       2018-07-31  409  	mutex_unlock(&system_transition_mutex);
25f2f3daa Rafael J. Wysocki 2008-06-11  410  
6e1819d61 Rafael J. Wysocki 2006-03-23 @411  	return error;
6e1819d61 Rafael J. Wysocki 2006-03-23  412  }
6e1819d61 Rafael J. Wysocki 2006-03-23  413  

:::::: The code at line 411 was first introduced by commit
:::::: 6e1819d615f24ce0726a7d0bd3dd0152d7b21654 [PATCH] swsusp: userland interface

:::::: TO: Rafael J. Wysocki <rjw@...k.pl>
:::::: CC: Linus Torvalds <torvalds@...osdl.org>

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ