From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98F79C433FE for ; Mon, 10 Oct 2022 11:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wg9Kn7MkJ3RY5PSxpFZZeYpaEc743XGm9zX1Y3tKtUo=; b=g7l+zoTPNsGR4i Kpw1GAN5/K7l52u78HJ9Kslqo6SowqL7b/OS1zdN/8EUNY95BQWvXy0W6kK3TIfZQHNSkuiL6yLLk NATLvxB/UIKiVyYm8LrYG3D8jZ5QMA3H9tMXxmnQhZ1tFUHcXlxbWkbU05wFd3YpqdUyGz+G9bUA8 Rc1dLkmt6kbP/93bvwPeN1oRBSXGjRb5rWtH4qeANDT0T9qXdIG9y/bKV5zQhtLe/Ek+w7CxJHiem 8dznQLg9ROmAo2GzVjjidSIt9tfXDk7KaupQUaUQ3DHrInmXguwz1EZoUVl7iiiMTkqLP/UqOdv09 RL206Y/jQP0SEMh+2Ihw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ohqcI-000WjG-Ds; Mon, 10 Oct 2022 11:06:38 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ohqcF-000WhP-2d for linux-arm-kernel@lists.infradead.org; Mon, 10 Oct 2022 11:06:36 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 84CDCB80E77 for ; Mon, 10 Oct 2022 11:06:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C573C433C1 for ; Mon, 10 Oct 2022 11:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665399992; bh=p20guC7JbhmvHgzm9d8sCMBUnajy1RNAbyXX6SeVkp0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XBlCOoZ47p0xWeSu2bZBdT2rUpSCm3oQD2Ou98TQeRQIHXjyUrKFfYWNbnfHnodCe 7WkdamgKpca5vcbtXFFrekdbNPO9UkdkDSiHX5zMVW0yfs8HteZlIJd8TGwl6XySE8 QIk0WntM02NbzBDBBlsOicT9XD0jkL1VMwfAQb9hK98DOuOo527DaIKYo4xCbHpaRx 8GWpS4z6zMV/RvcmLkR16pTgn4vWqxKbYq3A06k1GaxYc7AZKGW6rP43oxemQDNJXc qtSrepencBp90TR3nTJgt7M3ck6c24y5HMAAT+osB/VjS7z5oIsr7UZtefTy+tzFK/ ZnnVL82Huoung== Received: by mail-lf1-f47.google.com with SMTP id b2so16055674lfp.6 for ; Mon, 10 Oct 2022 04:06:32 -0700 (PDT) X-Gm-Message-State: ACrzQf13bheY83si0iN7KkhVk0CMUqNP2W4LOj6RuiT/YBZ/byLEzLA/ cfigAaGqCEsdhIvAT90iWK5qJlQnmI76hbc0EsE= X-Google-Smtp-Source: AMsMyM7nEc2ju6TICsd8RmqK7xJ4TdAiPz4O5ajV/lV0ZK9cJMBuJkisacoHBk4yfaBh2/W8xGkjaj1eRiHOS+kcBcU= X-Received: by 2002:a05:6512:2026:b0:4a2:3bb6:302 with SMTP id s6-20020a056512202600b004a23bb60302mr6421638lfs.539.1665399990179; Mon, 10 Oct 2022 04:06:30 -0700 (PDT) MIME-Version: 1.0 References: <20221010095346.1957-1-thunder.leizhen@huawei.com> <20221010095346.1957-2-thunder.leizhen@huawei.com> <1ab4c651-f0ab-1107-1784-ad255dabc33a@huawei.com> In-Reply-To: <1ab4c651-f0ab-1107-1784-ad255dabc33a@huawei.com> From: Ard Biesheuvel Date: Mon, 10 Oct 2022 13:06:19 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] ARM: Fix some check warnings of tool sparse To: "Leizhen (ThunderTown)" Cc: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221010_040635_435704_E9D4E5E8 X-CRM114-Status: GOOD ( 26.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. > > > >> if (is_wide_instruction(instr)) { > >> u16 inst2; > >> - inst2 = __mem_to_opcode_thumb16(((u16 *)pc)[1]); > >> + inst2 = __mem_to_opcode_thumb16(((__force u16 *)pc)[1]); > >> instr = __opcode_thumb32_compose(instr, inst2); > >> } > >> } else > >> #endif > >> - instr = __mem_to_opcode_arm(*(u32 *) pc); > >> + instr = __mem_to_opcode_arm(*(__force u32 *) pc); > >> } else if (thumb_mode(regs)) { > >> if (get_user(instr, (u16 __user *)pc)) > >> goto die_sig; > >> -- > >> 2.25.1 > >> > >> > >> _______________________________________________ > >> linux-arm-kernel mailing list > >> linux-arm-kernel@lists.infradead.org > >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > . > > > > -- > Regards, > Zhen Lei _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel