Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7323823pxb; Thu, 18 Feb 2021 07:16:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8WgrvL7FkDnY+9jsbmGkDownCdTPlJgfTpC9cV89GqPgL1V80Jg0gfzZMAC+rgtTITOhv X-Received: by 2002:a50:d987:: with SMTP id w7mr4593314edj.350.1613661367838; Thu, 18 Feb 2021 07:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613661367; cv=none; d=google.com; s=arc-20160816; b=b0atlKBFf9qLohmF8LQheRWFJnyU85ev0yUgrlx2DGzj1OVyCNuns9GpmRCQVbrgkQ EbcZXIzvsdtOjPEW5bNQo8+Nw5R2pFv+d+hDXMQh6Ygi275hySuPea7csLcJw4mihIya xBpz01+qOfTQ/+Rf2r2UpIDU5ij+8mXMu64x5CLkadHMQHB9tHx3SA5+LwyzECgzwhs1 rnZjN6hRedj5XZfCs3Yu8Ye6pRsBUtsGW0s8WZ2EHTDt+WnJZq4cCceDK16SXdSOvUlR vZfx0GAcbAkEM33eOrsWuOKwrmbdruXw8UgbKxHw9fseG/GLOhiSp/9lmk83dftK4lhe V5/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature:dkim-signature; bh=stzxJNn8WKxikkivrQDK9PXL40FKYp/YifYMqtAMfh4=; b=Mg7HeE3aRqduNsxoA8xvwFwVi2FsRTHnxpBhASK5TwKkkTvvxT1pTp/SCGPJo8qT7M Oi/Rfc+O5euZs4eHkkBRtxazKGJ2K4WSR3bKLjlAcQAAfFEK1UfJaBaVJp1LkKmWgaVo yJpTBU/u0pydLLzB7wfk6Bp6Tokf4FwGJOKEfKQ9VxXiqJ+Fh9dhOFxk9a5My0bbC0JU 3zc7Q9jVLgJddFoveZECutZIHdE81KFZMlV0k+BfbbZCmVmqkHEBrhvmeuNPNeHs7YX2 N/90pFOSW4NuDn+qNgx3WYANbH2C/7PU4Ca/Up81DZmxdRlXZ+sbkmQCWxzOlhwSJ1ms CH9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@g001.emailsrvr.com header.s=20190322-9u7zjiwi header.b=Uvzbd8pW; dkim=pass header.i=@mev.co.uk header.s=20190130-41we5z8j header.b="mxHpE7/I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb4si4081686ejb.642.2021.02.18.07.15.43; Thu, 18 Feb 2021 07:16:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@g001.emailsrvr.com header.s=20190322-9u7zjiwi header.b=Uvzbd8pW; dkim=pass header.i=@mev.co.uk header.s=20190130-41we5z8j header.b="mxHpE7/I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbhBRPMD (ORCPT + 99 others); Thu, 18 Feb 2021 10:12:03 -0500 Received: from smtp104.ord1c.emailsrvr.com ([108.166.43.104]:39517 "EHLO smtp104.ord1c.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232889AbhBRM56 (ORCPT ); Thu, 18 Feb 2021 07:57:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=g001.emailsrvr.com; s=20190322-9u7zjiwi; t=1613646257; bh=bRHGiPfH836yATcVWrHjPVJ2UIR0s0z9fjqDlTxmMwU=; h=Subject:To:From:Date:From; b=Uvzbd8pW9YpNoNmRWuZQuU09cnY8OVavkWuRGk0F3AbhSPJdhtlHmvROrP4Jnbrsb ab5z9+KNb4GwTW4oZzBaCFfA0JuLQS8wX56FoL8crrMByJ3sIeSdOZRx+FxTEw/keU XZfD8jBbPBPqYZYdwmnfDyfru3W4ojBqjA83VPCY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20190130-41we5z8j; t=1613646257; bh=bRHGiPfH836yATcVWrHjPVJ2UIR0s0z9fjqDlTxmMwU=; h=Subject:To:From:Date:From; b=mxHpE7/IfiF+E46WkES6g1s5LsiGUka43NKrw4cDNQ1oOWDf5gpdKlev+EuQnF7ek dVb2VIh2LNXTVLyYdPsdGxzWModMDqePGT4LIBAvtYug/Ai8UYSQdaQFDrCd2JVqti 5EEC8exiRZ82Ylp4SHH54PMmcoTQcmTWQHMcJvys= X-Auth-ID: abbotti@mev.co.uk Received: by smtp22.relay.ord1c.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id D16F0E0118; Thu, 18 Feb 2021 06:04:16 -0500 (EST) Subject: Re: [PATCH] staging: comedi: cast to (unsigned int *) To: Greg KH , Atul Gopinathan Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20210217165907.9777-1-atulgopinathan@gmail.com> <20210217181000.GB10124@atulu-ubuntu> From: Ian Abbott Organization: MEV Ltd. Message-ID: <3cfef23d-8d4a-205c-61e8-cbe8c9a0c0f4@mev.co.uk> Date: Thu, 18 Feb 2021 11:04:15 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Classification-ID: 4bf05355-9fc5-4567-9578-f928f84fb8a2-1-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/02/2021 18:26, Greg KH wrote: > On Wed, Feb 17, 2021 at 11:40:00PM +0530, Atul Gopinathan wrote: >> On Wed, Feb 17, 2021 at 06:35:15PM +0100, Greg KH wrote: >>> On Wed, Feb 17, 2021 at 10:29:08PM +0530, Atul Gopinathan wrote: >>>> Resolve the following warning generated by sparse: >>>> >>>> drivers/staging//comedi/comedi_fops.c:2956:23: warning: incorrect type in assignment (different address spaces) >>>> drivers/staging//comedi/comedi_fops.c:2956:23: expected unsigned int *chanlist >>>> drivers/staging//comedi/comedi_fops.c:2956:23: got void [noderef] * >>>> >>>> compat_ptr() has a return type of "void __user *" >>>> as defined in "include/linux/compat.h" >>>> >>>> cmd->chanlist is of type "unsigned int *" as defined >>>> in drivers/staging/comedi/comedi.h" in struct >>>> comedi_cmd. >>>> >>>> Signed-off-by: Atul Gopinathan >>>> --- >>>> drivers/staging/comedi/comedi_fops.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c >>>> index e85a99b68f31..fc4ec38012b4 100644 >>>> --- a/drivers/staging/comedi/comedi_fops.c >>>> +++ b/drivers/staging/comedi/comedi_fops.c >>>> @@ -2953,7 +2953,7 @@ static int get_compat_cmd(struct comedi_cmd *cmd, >>>> cmd->scan_end_arg = v32.scan_end_arg; >>>> cmd->stop_src = v32.stop_src; >>>> cmd->stop_arg = v32.stop_arg; >>>> - cmd->chanlist = compat_ptr(v32.chanlist); >>>> + cmd->chanlist = (unsigned int __force *)compat_ptr(v32.chanlist); >>> >>> __force? That feels wrong, something is odd if that is ever needed. >>> >>> Are you _sure_ this is correct? >> >> The same file has instances of "(usigned int __force *)" cast being >> used on the same "cmd->chanlist". For reference: >> >> At line 1797 of comedi_fops.c: >> 1796 /* restore chanlist pointer before copying back */ >> 1797 cmd->chanlist = (unsigned int __force *)user_chanlist; >> 1798 cmd->data = NULL; >> >> At line 1880: >> 1879 /* restore chanlist pointer before copying back */ >> 1880 cmd->chanlist = (unsigned int __force *)user_chanlist; >> 1881 *copy = true; >> >> Here "user_chanlist" is of type "unsigned int __user *". >> >> >> Or perhaps, I shouldn't be relying on them? > > I don't know, it still feels wrong. > > Ian, any thoughts? It's kind of moot anyway because the patch is outdated. But the reason for the ___force is that the same `struct comedi_cmd` is used in both user and kernel contexts. In user contexts, the `chanlist` member points to user memory and in kernel contexts it points to kernel memory (copied from userspace). The sparse tagging of this member has flip-flopped a bit over the years: * commit 92d0127c9d24 ("Staging: comedi: __user markup on comedi_fops.c") (May 2010) tagged it as `__user`. * commit 9be56c643263 ("staging: comedi: comedi.h: remove __user tag from chanlist") (Sep 2012) removed the `__user` tag. It is mostly used in a kernel context, for example all the low-level drivers with `do_cmd` and `do_cmdtest` handlers use it in kernel context. The alternative would be to have a separate kernel version of this struct, but it would be mostly identical to the user version apart from the sparse tagging of this member and perhaps the removal of the unused `data` and `data_len` members (which need to be kept in the user version of the struct for compatibility reasons). -- -=( Ian Abbott || MEV Ltd. is a company )=- -=( registered in England & Wales. Regd. number: 02862268. )=- -=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=- -=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-