security/security.c:3966:8-15: WARNING opportunity for memdup_user
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git next-queue head: 48698f2e49eb79afb90363e2f68957e2836599c9 commit: 357595fcb7c7dcd515c66e92813d53fc8074809a [11/19] LSM: syscalls for current process attributes config: x86_64-randconfig-103-20231026 (https://download.01.org/0day-ci/archive/20231027/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20231027/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
cocci warnings: (new ones prefixed by >>)
>> security/security.c:3966:8-15: WARNING opportunity for memdup_user
vim +3966 security/security.c
3933
3934 /*
3935 * Please keep this in sync with it's counterpart in security/lsm_syscalls.c
3936 */
3937
3938 /**
3939 * security_setselfattr - Set an LSM attribute on the current process.
3940 * @attr: which attribute to set
3941 * @uctx: the user-space source for the information
3942 * @size: the size of the data
3943 * @flags: reserved for future use, must be 0
3944 *
3945 * Set an LSM attribute for the current process. The LSM, attribute
3946 * and new value are included in @uctx.
3947 *
3948 * Returns 0 on success, -EINVAL if the input is inconsistent, -EFAULT
3949 * if the user buffer is inaccessible, E2BIG if size is too big, or an
3950 * LSM specific failure.
3951 */
3952 int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,
3953 size_t size, u32 flags)
3954 {
3955 struct security_hook_list *hp;
3956 struct lsm_ctx *lctx;
3957 int rc = LSM_RET_DEFAULT(setselfattr);
3958
3959 if (flags)
3960 return -EINVAL;
3961 if (size < sizeof(*lctx))
3962 return -EINVAL;
3963 if (size > PAGE_SIZE)
3964 return -E2BIG;
3965
> 3966 lctx = kmalloc(size, GFP_KERNEL);
3967 if (lctx == NULL)
3968 return -ENOMEM;
3969
3970 if (copy_from_user(lctx, uctx, size)) {
3971 rc = -EFAULT;
3972 goto free_out;
3973 }
3974
3975 if (size < lctx->len || size < lctx->ctx_len + sizeof(*lctx) ||
3976 lctx->len < lctx->ctx_len + sizeof(*lctx)) {
3977 rc = -EINVAL;
3978 goto free_out;
3979 }
3980
3981 hlist_for_each_entry(hp, &security_hook_heads.setselfattr, list)
3982 if ((hp->lsmid->id) == lctx->id) {
3983 rc = hp->hook.setselfattr(attr, lctx, size, flags);
3984 break;
3985 }
3986
3987 free_out:
3988 kfree(lctx);
3989 return rc;
3990 }
3991
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki