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]
Date:   Mon, 24 Oct 2022 17:39:59 -0700
From:   Casey Schaufler <casey@...aufler-ca.com>
To:     Kees Cook <keescook@...omium.org>
Cc:     casey.schaufler@...el.com, paul@...l-moore.com,
        linux-security-module@...r.kernel.org, linux-audit@...hat.com,
        jmorris@...ei.org, selinux@...r.kernel.org,
        john.johansen@...onical.com, penguin-kernel@...ove.sakura.ne.jp,
        stephen.smalley.work@...il.com, linux-kernel@...r.kernel.org,
        casey@...aufler-ca.com
Subject: Re: [PATCH v38 39/39] LSM: Create lsm_module_list system call

On 10/12/2022 3:04 PM, Kees Cook wrote:
> On Tue, Sep 27, 2022 at 01:31:55PM -0700, Casey Schaufler wrote:
>> +SYSCALL_DEFINE3(lsm_module_list,
>> +	       unsigned int __user *, ids,
>> +	       size_t __user *, size,
>> +	       int, flags)
> Please make this unsigned int.

Sure.


>> +{
>> +	unsigned int *interum;
>> +	size_t total_size = lsm_id * sizeof(*interum);
>> +	size_t usize;
>> +	int rc;
>> +	int i;
> Please test that flags == 0 so it can be used in the future:
>
> 	if (flags)
> 		return -EINVAL;

Yup.

>> +
>> +	if (get_user(usize, size))
>> +		return -EFAULT;
>> +
>> +	if (usize < total_size) {
>> +		if (put_user(total_size, size) != 0)
>> +			return -EFAULT;
>> +		return -E2BIG;
>> +	}
>> +
>> +	interum = kzalloc(total_size, GFP_KERNEL);
>> +	if (interum == NULL)
>> +		return -ENOMEM;
>> +
>> +	for (i = 0; i < lsm_id; i++)
>> +		interum[i] = lsm_idlist[i]->id;
>> +
>> +	if (copy_to_user(ids, interum, total_size) != 0 ||
>> +	    put_user(total_size, size) != 0)
>> +		rc = -EFAULT;
> No need to repeat this, if it is written first.
>
>> +	else
>> +		rc = lsm_id;
>> +
>> +	kfree(interum);
>> +	return rc;
> No need for the alloc/free. Here's what I would imagine for the whole
> thing:

A better approach. Thank you.

>
> 	if (flags)
> 		return -EINVAL;
>
> 	if (get_user(usize, size))
> 		return -EFAULT;
>
> 	if (put_user(total_size, size) != 0)
> 		return -EFAULT;
>
> 	if (usize < total_size)
> 		return -E2BIG;
>
> 	for (i = 0; i < lsm_id; i++)
> 		if (put_user(lsm_idlist[i]->id, id++))
> 			return -EFAULT;
>
> 	return lsm_id;
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ