[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Y8fXu92IySboNxVY@li-4a3a4a4c-28e5-11b2-a85c-a8d192c6f089.ibm.com>
Date: Wed, 18 Jan 2023 12:27:55 +0100
From: Alexander Gordeev <agordeev@...ux.ibm.com>
To: Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
Cc: vneethv@...ux.ibm.com, oberpar@...ux.ibm.com, hca@...ux.ibm.com,
gor@...ux.ibm.com, borntraeger@...ux.ibm.com, svens@...ux.ibm.com,
linux-s390@...r.kernel.org, linux-kernel@...r.kernel.org,
Abaci Robot <abaci@...ux.alibaba.com>
Subject: Re: [PATCH v2] s390/chsc: Switch over to memdup_user()
On Wed, Jan 18, 2023 at 05:58:23PM +0800, Jiapeng Chong wrote:
> Use memdup_user rather than duplicating its implementation, this is a
> little bit restricted to reduce false positives.
>
> ./drivers/s390/cio/chsc_sch.c:703:7-14: WARNING opportunity for
> memdup_user.
>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=3785
> Reported-by: Abaci Robot <abaci@...ux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
> ---
> Changes in v2:
> -Add free_page((unsigned long)sccl_area);
>
> drivers/s390/cio/chsc_sch.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
> index 180ab899289c..09dcce7ff24b 100644
> --- a/drivers/s390/cio/chsc_sch.c
> +++ b/drivers/s390/cio/chsc_sch.c
> @@ -700,15 +700,13 @@ static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
> sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
> if (!sccl_area)
> return -ENOMEM;
> - ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
> - if (!ccl) {
> - ret = -ENOMEM;
> - goto out_free;
> - }
> - if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
> - ret = -EFAULT;
> - goto out_free;
> +
> + ccl = memdup_user(user_ccl, sizeof(*ccl));
> + if (IS_ERR(ccl)) {
> + free_page((unsigned long)sccl_area);
> + return PTR_ERR(ccl);
> }
> +
> sccl_area->request.length = 0x0020;
> sccl_area->request.code = 0x0030;
> sccl_area->fmt = ccl->req.fmt;
Such a change would have to address other similar patterns in this source.
Besides, it is not that obvious that swapping GFP_KERNEL for GFP_USER
(memdup_user() is called with) is issue-free.
Powered by blists - more mailing lists