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: 168379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1336176vqb; Wed, 22 Nov 2023 05:52:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+SPBjjv+yOHEF4PH1Bgs0A+oFDmjo7dnkl9g4Y+2w+u1FuW83iohMw68+IUh+c6gaJCon X-Received: by 2002:a17:90b:3792:b0:27d:22ed:8e9e with SMTP id mz18-20020a17090b379200b0027d22ed8e9emr2606092pjb.6.1700661142707; Wed, 22 Nov 2023 05:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700661142; cv=none; d=google.com; s=arc-20160816; b=O12LA1MOmnUA4Sg83TvpO65iCOaAwC4vQQL5c1wGnT248H3GdJegrLLI/JwxixY53u pxx/BC7Su50Ydb+y01tEWdhszgPFWKibkNHDWZHAj8rtrCIhzIIdh0pvjb+v3XfAnBI6 dhvYT+HZ3cwP8sTIQSrjd5gaC3IGHpHVdjqCy762zDmRrc2CO9HH8kZSzev/ZQBUNuAq WUrk0yn61RV8Ks1tB3jFYLDSNmPRVyDocuT6GAE9OE8z50qn61S5WRFbpxjOq2vlgnQI cu5vtgyqtl4ehwkTExr+ABszW5fcCzOtYDwlOM5XftIrcWIjoxEuQoyUI4yteGNgjPk6 4UmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=P7husD+9d3F1Gv9OOp27OuBbyYe5n6sJHNp6uS06FL8=; fh=EdyLYATM/qh8Las/bR8YboFDIgMgjckTtwTT8v291sg=; b=v/K4BWiqjs9iH17Ox+/eUAKoNCeEnCqZZhaEy/SaPd1P1Ds7u3BqJiC3iQ1PJBH7o2 bNccZQqrn9JVIHUB+goUwE3UzglkyWWRaXgvvNw9wS6UMaue0CbPBLPIBFuxRiql2Z3e 6j4jVGiRpN/5MrvUKr4cHKfEFu5MPPbWpjHsAoxCUDU0i++iW601ytLZGGOHQU5PB4tb kkDj4fNSY2T3xCI6+0waHoMA+zGxckpDV2KvauFo1RYd2fe+76nDP2F9v9V4nJ8dvJJk VO4d0U89tkzcsPQaLGubRpDluW48hryACW7JTLQN80C2oci/Ay9mh2BZQutQeVvgmOUb ylWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GITl4jk+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t2-20020a17090abc4200b0028023efb800si1485021pjv.18.2023.11.22.05.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 05:52:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GITl4jk+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 66D8B82162ED; Wed, 22 Nov 2023 05:52:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344244AbjKVNwI (ORCPT + 99 others); Wed, 22 Nov 2023 08:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343568AbjKVNwH (ORCPT ); Wed, 22 Nov 2023 08:52:07 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79C93101 for ; Wed, 22 Nov 2023 05:52:03 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-280cd4e6f47so1483701a91.1 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=vger.kernel.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=GITl4jk+oxBwXrszNoXyNcJPHcH1PiihIC+kFMtYKY1TIJeJ3VzrN3KN5d6LeQjFif tExWUi+U2pwYjMov1dcxUPENVTsLO7IzBD/EnVq8rygWNZxerP+JkgahMiUwc1QUtIAL eN/GyZyViieWG0hKyLqM4xXVFePPqrvAXbqZZCML8k9yO05genOr4ux4JG52eLX3C03j LSR7rT1mU3k2kRsbgXDQDZEdvu1RL6iGPE2cBQqBITPCdbl5pE29XmJ6ZzRkzxTQDpLe nSjYZmDcvzxcWZGHVvzmWbVMjv+RJoU1gA68CIbvBkzdx3TSLK+G9ooNN5++iAywFki9 3WFg== 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=cJaZ1EZjwxoTHD4we3ZmBdiTjLg6DMQR0Dt9LcDtJtkPHCdLKfFAFDJppdTbGX6M1q JTpYxGoNCvgkg+U2TshEnQa7tGTGm8duuDpfk7yWK/dhzZg9fPj1UwQYFwhV7PiD8pfw s6KKbNwWnHdr+mP74uG8QO4nUK37XBAPEHAg6PvtKF+dSYZcumYExTG8uItXQupY/FQ1 cxBMMTIP1QXG3PJBHYDz4O9orEyG+AGpD+wC7NMiaa3JlqopkuW4LgZbp9wjmvpNcaa/ 9xQdM0cxu7ZNpXfLqw38x6M7WwGojc0tsbjfxlPuYsbL+xasHVjV3EJS+0gZ6bSbRRac SHmw== X-Gm-Message-State: AOJu0YwvJCMdhiq7J/3eai4IjoINximZilwA/w2IBGevJKqRJ77HsfAQ FCDh1FFS8ndg1CQipH2agbirpA== 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 05:52:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783272458598816194 X-GMAIL-MSGID: 1783272458598816194 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;