From patchwork Wed Nov 22 13:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13464926 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 BBECEC61D97 for ; Wed, 22 Nov 2023 13:52:30 +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:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=m6D+oOTiGvMbBFVePrtjzpFDheThv+j1p0WtP70hK6A=; b=RcAQuDupKTfdMT n5vcxllm3/HxYC2nGRxB+7prLWi8wnUVuFgWblgkrSutDUqDhB7Qnd4vV0NMfHz5z15Pf8sV2Rb2x FbVlt0f1h94yeTzqjhs4qZplDLsFoomxnXFEN6OfEgOep55bk0qEK6LjUN41ctzZS2+24sOrqmdAP 65/uuDvX3an9tgzR16fJydDNO4kdO6g41FNd+HoqOnzk1vSgQQbkmrywuKN8dKaAyxnuHLV/jdVe6 F3EAkOaPpGnhhK2C6/sSEY1FAvHfXFLOXAtnXicbp24Wx4UVFY1n3+MiguKaW1RQhxVXZIvsuCsVF 8b93FWvwiIwzqRZXmD7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5neO-0021gO-1b; Wed, 22 Nov 2023 13:52:20 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5neA-0021Z9-02 for linux-riscv@lists.infradead.org; Wed, 22 Nov 2023 13:52:18 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-28554922cebso3148a91.0 for ; Wed, 22 Nov 2023 05:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700661123; x=1701265923; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=P7husD+9d3F1Gv9OOp27OuBbyYe5n6sJHNp6uS06FL8=; b=qyPUZ4V5+Kc6jG3+k8Lk3Dt+QJ47MSQCMohcNkT2I2T1GgVnC3SBFNSY7Jvun844N0 kjz0mYnIgGHFvZ1ZojmS8MzdScVllqYjM/HiTgZY4U1RouDTUf7khspxh3As2eiEjKtM 7qcLOcPK47+XxVqqqZ73+P1ilmeaGN41TuRKIK5Ct3syq/hcUSICLyF9f6OiKClkNAql 6V/bCBWlNl6hb0/ZMiEAgYZ35apAnMrArPNtwOfSJpdM+GW3oUE5hPzBiHiBLGvtKgPB B92jNH8UAboodOk1ON+BP4Ek84d9lIIrWNdE7lWrq6Pn750/GYQtMfBsyVZt7l0QmnvG dTRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700661123; x=1701265923; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=P7husD+9d3F1Gv9OOp27OuBbyYe5n6sJHNp6uS06FL8=; b=oTijIVe301pLEpHfWupiC+3oglQKV12HhStG4N0Aq6IoSqZa3JBFGGaRVwtODE+zq0 qQGrkZqGPqfmYYHpREsGuxxI5NkmkxeBU8B3j5FNsjJyQs4HO1Rzn5x5QlypKgPXkfVI cjd7FW8pMN97OLPkz6CZqbch7tXqKa6CkTTIKI7+UIffK+G2ifNgefVSUDbVrxUcu4hL 9n5ABrvUKU6FUeV+adHTzM2lEcItWGDPLoWDM2Ft0t7jtqCcg9Gwupr4pX96jWNrdZ6r 00u+VOkFOlgarJtre52OAq/6RHu8BtcTk3Z97thtyaXODyHDNyCI2mYRfFlx3F19btyb jgSQ== X-Gm-Message-State: AOJu0YzjPAefzZTu4QnBPlam6M6lKxEIDQXXHBjq7bHbG/MQKPNoSE0+ iNVevQWM2GoNHlLma5jvSjoJqEj4uFfJhltNitc= X-Google-Smtp-Source: AGHT+IE5Dg+TMXVzZNn0mFXompSbIgWw4KFeIm5Q5UstyfAp14qFST/CkbxoGCVx/IGuAn9WPK835w== X-Received: by 2002:a17:90b:d8a:b0:285:e55:68b8 with SMTP id bg10-20020a17090b0d8a00b002850e5568b8mr2374428pjb.1.1700661122833; Wed, 22 Nov 2023 05:52:02 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:edca:1f11:8726:b116]) by smtp.gmail.com with ESMTPSA id rj1-20020a17090b3e8100b0028031e87660sm1387947pjb.16.2023.11.22.05.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 05:52:02 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , kernel test robot Subject: [PATCH] riscv: fix incorrect use of __user pointer Date: Wed, 22 Nov 2023 14:51:41 +0100 Message-ID: <20231122135141.2936663-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231122_055206_278103_D5625472 X-CRM114-Status: GOOD ( 12.32 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org These warnings were reported by sparse and were due to lack of __user annotation as well as dereferencing such pointer. Fix this by adding __user cast were needed (load_u8()/store_u8()) and move the __user annotation in __read_insn() into the if() branch that uses __get_user() with this pointer. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202311160606.obGOOwB3-lkp@intel.com/ Signed-off-by: Clément Léger --- arch/riscv/kernel/traps_misaligned.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index 5eba37147caa..02abb6616873 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -319,7 +319,7 @@ static inline int get_insn(struct pt_regs *regs, ulong mepc, ulong *r_insn) static inline int load_u8(struct pt_regs *regs, const u8 *addr, u8 *r_val) { if (user_mode(regs)) { - return __get_user(*r_val, addr); + return __get_user(*r_val, (u8 __user *)addr); } else { *r_val = *addr; return 0; @@ -329,7 +329,7 @@ static inline int load_u8(struct pt_regs *regs, const u8 *addr, u8 *r_val) static inline int store_u8(struct pt_regs *regs, u8 *addr, u8 val) { if (user_mode(regs)) { - return __put_user(val, addr); + return __put_user(val, (u8 __user *)addr); } else { *addr = val; return 0; @@ -341,7 +341,7 @@ static inline int store_u8(struct pt_regs *regs, u8 *addr, u8 val) int __ret; \ \ if (user_mode(regs)) { \ - __ret = __get_user(insn, insn_addr); \ + __ret = __get_user(insn, (typeof(*insn_addr) __user *) insn_addr); \ } else { \ insn = *insn_addr; \ __ret = 0; \ @@ -356,7 +356,7 @@ static inline int get_insn(struct pt_regs *regs, ulong epc, ulong *r_insn) if (epc & 0x2) { ulong tmp = 0; - u16 __user *insn_addr = (u16 __user *)epc; + u16 *insn_addr = (u16 *)epc; if (__read_insn(regs, insn, insn_addr)) return -EFAULT; @@ -376,7 +376,7 @@ static inline int get_insn(struct pt_regs *regs, ulong epc, ulong *r_insn) return 0; } else { - u32 __user *insn_addr = (u32 __user *)epc; + u32 *insn_addr = (u32 *)epc; if (__read_insn(regs, insn, insn_addr)) return -EFAULT;