Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1005416rwi; Mon, 10 Oct 2022 09:55:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4lWE/Aa5z3fPdeLwTannqx7kVI+JA5F+8vgYoMftoO+kAA6v9rSSSFbjYVdDYCMGHzfguM X-Received: by 2002:aa7:dd45:0:b0:458:7474:1fbe with SMTP id o5-20020aa7dd45000000b0045874741fbemr18808912edw.334.1665420911441; Mon, 10 Oct 2022 09:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665420911; cv=none; d=google.com; s=arc-20160816; b=CUJjzQflHwv541wy3t6vpaxDWdhjtPmxlmq9a5EmP/I7KewcLPyCldOrdvH9UgQpp1 Wxjf1R9TJfHZp+hWHG+3J1dsdmDXOxepW/R/OYfoB/pzc4aCNaXT0UZF2JWfk16SLWrN FwLxBq++XItucpfvoqBOPUo+844ueGLEI0bsrnpXLWR0PGDVxhNdnZDbDXAd3RzaxIYa cObGjHOWANZm6hurvJFZJDrGUEpPBtl0pCUDihDnY3dntOKFr+aUonqgyTajYEClf2eh cXE8oon0DYIPFmhsplIp0rjvtRZSrWq/hUCgVlw78a5/lrHpV0iqhsd2juFGn2pFF9ay +6RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ahQ+98OF54Kz7CPYTtQaC2pDJITFFBkkmpWlqrKppU8=; b=det+WvhM7LVuLuHTTbItqiySA+W/Hh2RzaNA2xIlgFR+CCgQlzINv2D4wYfFciLCR+ I9H/32OYkDE0aX8U0SVaO1oqYifwW+iYDQl+5HGErWpjevpdFkFOLhjbr1V0k3thvvpt KNPHYmptrG7x9TmM4zGj55llLBaGoRjpdygan6ziBBa7MUc26hnm9PPJPblBxBPZhC21 BqN/PdBu4cj5GG9oZSfV+mFzfZSgL0KYGX8N+KQrJVYDdrlGVJ+m78B7TdXQ0Q9eUh0v LcIxy8j0jIImrbtvpy3sQssH5BcoV8yiskf5t9Mv7bYEOTFcGkLVo7K2BqBBJDjPgWJf EUbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=WgaEd+Du; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw18-20020a1709066a1200b0078dd0fb7a46si237833ejc.427.2022.10.10.09.54.45; Mon, 10 Oct 2022 09:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=WgaEd+Du; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229563AbiJJQSE (ORCPT + 99 others); Mon, 10 Oct 2022 12:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiJJQSC (ORCPT ); Mon, 10 Oct 2022 12:18:02 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D86CB5C37F for ; Mon, 10 Oct 2022 09:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ahQ+98OF54Kz7CPYTtQaC2pDJITFFBkkmpWlqrKppU8=; b=WgaEd+Du5L9THoK0ff07avq0Vo RBL5BjmiJQI/jpx2btFYE1qY6mVm4kcfQxQTR982Oko7tdLS8pHlcXdXG42GxDcKxsWJE+9kMARv4 atu05I6qQDbM6YIgTSw7i4Q7vriDRpCv/tqFtPQ50pKaLsGQKAVdGrfPM/rTNJ6K7wi4MAPjmUnmn /FfGKkUBOZrs8JAdTRFUw63JZKBhwBbcAHAzeeNc1W01puxST/qtjwGBwp+/7f2bfmzGsdU4adrR2 RBPBTInxYzfpIQNx4lRk6RXtccKwRHS2oc6p0JyoGgRQO3olLAQynaPh09r8j6+IQasx4QVGdqQWg DDv/zdgw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:34670) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ohvTX-0004sb-W0; Mon, 10 Oct 2022 17:17:56 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1ohvTX-0001zA-DM; Mon, 10 Oct 2022 17:17:55 +0100 Date: Mon, 10 Oct 2022 17:17:55 +0100 From: "Russell King (Oracle)" To: Ard Biesheuvel Cc: "Leizhen (ThunderTown)" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] ARM: Fix some check warnings of tool sparse Message-ID: References: <20221010095346.1957-1-thunder.leizhen@huawei.com> <20221010095346.1957-2-thunder.leizhen@huawei.com> <1ab4c651-f0ab-1107-1784-ad255dabc33a@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 10, 2022 at 06:14:56PM +0200, Ard Biesheuvel wrote: > On Mon, 10 Oct 2022 at 18:08, Russell King (Oracle) > wrote: > > > > On Mon, Oct 10, 2022 at 01:06:19PM +0200, Ard Biesheuvel wrote: > > > On Mon, 10 Oct 2022 at 12:58, Leizhen (ThunderTown) > > > wrote: > > > > > > > > > > > > > > > > On 2022/10/10 18:20, Ard Biesheuvel wrote: > > > > > On Mon, 10 Oct 2022 at 11:56, Zhen Lei wrote: > > > > >> > > > > >> Fix the following warnings: > > > > >> warning: incorrect type in initializer (different address spaces) > > > > >> expected unsigned short [noderef] __user *register __p > > > > >> got unsigned short [usertype] * > > > > >> warning: cast removes address space '__user' of expression > > > > >> > > > > >> Signed-off-by: Zhen Lei > > > > >> --- > > > > >> arch/arm/kernel/traps.c | 10 +++++----- > > > > >> 1 file changed, 5 insertions(+), 5 deletions(-) > > > > >> > > > > >> diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c > > > > >> index 20b2db6dcd1ced7..34aa80c09c508c1 100644 > > > > >> --- a/arch/arm/kernel/traps.c > > > > >> +++ b/arch/arm/kernel/traps.c > > > > >> @@ -188,9 +188,9 @@ static void dump_instr(const char *lvl, struct pt_regs *regs) > > > > >> } > > > > >> } else { > > > > >> if (thumb) > > > > >> - bad = get_user(val, &((u16 *)addr)[i]); > > > > >> + bad = get_user(val, &((u16 __user *)addr)[i]); > > > > >> else > > > > >> - bad = get_user(val, &((u32 *)addr)[i]); > > > > >> + bad = get_user(val, &((u32 __user *)addr)[i]); > > > > >> } > > > > >> > > > > >> if (!bad) > > > > >> @@ -455,15 +455,15 @@ asmlinkage void do_undefinstr(struct pt_regs *regs) > > > > >> if (processor_mode(regs) == SVC_MODE) { > > > > >> #ifdef CONFIG_THUMB2_KERNEL > > > > >> if (thumb_mode(regs)) { > > > > >> - instr = __mem_to_opcode_thumb16(((u16 *)pc)[0]); > > > > >> + instr = __mem_to_opcode_thumb16(((__force u16 *)pc)[0]); > > > > > > > > > > Shouldn't this be __user as well? (and below) > > > > > > > > unsigned int instr; > > > > void __user *pc; > > > > > > > > The __user can clear the warning, but a new warning will be generated. > > > > > > > > instr = __mem_to_opcode_thumb16(((u16 *)pc)[0]); > > > > ^new ^old > > > > > > > > arch/arm/kernel/traps.c:473:33: warning: dereference of noderef expression > > > > > > > > > > This is because dereferencing a __user pointer is not permitted. > > > > > > So this code should be using get_kernel_nofault() here not a plain > > > dereference of PC. So better to fix that properly instead of papering > > > over it with a __force cast just to make sparse happy. > > > > Why? We won't get here unless the PC can be dereferenced. If it's not > > able to be dereferenced, then we'd be dealing with a prefetch abort. > > > > If that is guaranteed (i.e., there is no way we might be racing with a > module unload on another CPU or something like that), then I agree > that dereferencing PC is fine. If we get here for an instruction in a module that's being unloaded, we have way bigger problems. We shouldn't be executing code in a module being unloaded in the first place. That becomes a case of "deserves to oops". The more likely case would be a prefetch abort when the page is unmapped. You'd have to try pretty hard to get an undef to race with a module unload. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!