Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp509236rwp; Wed, 12 Jul 2023 17:41:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYo2rBEmdei0WUrHaoupORs8LMsKTZ18T3kXzTdV38fVxG2ACEw50jt0y8h0gw4T773nyQ X-Received: by 2002:a17:90a:8a88:b0:25b:d4bc:28d4 with SMTP id x8-20020a17090a8a8800b0025bd4bc28d4mr18618242pjn.40.1689208862092; Wed, 12 Jul 2023 17:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689208862; cv=none; d=google.com; s=arc-20160816; b=qKJpfOPzgAmgRWT1AvZ6Yz+H5q4bMz4aNwtSVJ5YnJf82Jnl2v3Wq0moLtPOBJcRZE NGRq8BNza1MxjbuXe4/gKXeOX9OppQbfULweN2ej2KUCjHk2YkbM3CaSf9YvcfYTDFYg E54jLKfXG6RpfnDf9rqlh5oexxtiRwJfB10oiGBOaCY9iNKnzzdF2u4S5rSFBqQiXvcp omYP0+mT9ypprcSKtpUpmXjZW/C5IBnI9mRjyq3e5ycokX/8rzlLX5XKde0c3PuwTpY1 6hfKgJ7VNs3VxJ9OPlm1dYTIi9v/21DOU/3HmMgu6VMQhx/5GFMP/7uOo1NAAU6v8weH CNuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=NuP6Oxv4qBDsEckZKNAT5qyZlidjFyUwVL90dnw1nJo=; fh=sL3Tmm7blUmQQwHDf35mXwMOeMdvmon6d1Qjv4Dx0v8=; b=SQNHr/a997MWHgoVyweD37CNtJTEF4Sqsr/ZpxXSQ8HeU/tX6nzhQdmlxI+qwNypuI I2SoFlnkRApt6gn5KN/YSdH+wt0+W1Zq95t8TH5SwWpcjPejNBSMl4tSq+4gLifT+Tkb bwAxbSlApQN/EuzwSfuhU0mhK/oYaIF9q8eMHQ1qQWFDwHH8YhfRHsr2QST9DNSK2FhH As7g/baOEhMKpBZ8wKPiJpKJ2dwSMHvfijbi3mQioJWYnPscNw5rQuXDUxs4qILwX8d/ 2CSCFYLqogaNopChNXZtmD84E6u7q4W0rU9Nd/+oxSGpxn6aSaMGKRblCwLAGWuomrQJ fPpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CCaEzlcj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m23-20020a6562d7000000b005573ea250f0si3934811pgv.116.2023.07.12.17.40.50; Wed, 12 Jul 2023 17:41:02 -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=pass header.i=@kernel.org header.s=k20201202 header.b=CCaEzlcj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbjGMAAh (ORCPT + 99 others); Wed, 12 Jul 2023 20:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjGMAAg (ORCPT ); Wed, 12 Jul 2023 20:00:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D8BE1BF6 for ; Wed, 12 Jul 2023 17:00:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 52D24619AF for ; Thu, 13 Jul 2023 00:00:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9394C433CA for ; Thu, 13 Jul 2023 00:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689206433; bh=m45Eh51GK33EfykT/kNO3/YeUg+Yoa9HKS4dDxqE0rk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CCaEzlcjriTjavqYQVOTOB6EsstWPysLatVaXgEL/u5HGSogUw2l7BywOrVgxasUI Jz92tvE079LpxJP+x2YRaFchKVUX+vyfUW2rWfKvYKRk7yoW/LZvrRIbunivAiO4Vg WtRbuB6dUOY5pSnmLd+orHKzSHWViRoMAn0SppLvy6WXmmsKI5eylBB/uD9hUUuHxe ZCWbRIP1f99l2Qz+FtFWwPZUy/uqRoNqavUvk749Hk9KjawIkCnIUtdktfAuce72cl Dq4XWbFuKL2QTOgdb6inPxdQehwjR+ZaIXDXmypwkwQBE6sr2GUhk0v7yTIXtHIHHb GIpAqJTZIRfZg== Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3094910b150so233975f8f.0 for ; Wed, 12 Jul 2023 17:00:33 -0700 (PDT) X-Gm-Message-State: ABy/qLYRYBcqFC9VWhmVRDh58v4d58EYt4JAeLpS50X2JfUfhyn7yXPF NC8C+zc8s+Eo5G0DuuBw5CQf09wiO+AIuILH2Tw= X-Received: by 2002:adf:f44d:0:b0:30a:ec3b:58d8 with SMTP id f13-20020adff44d000000b0030aec3b58d8mr21784626wrp.3.1689206431973; Wed, 12 Jul 2023 17:00:31 -0700 (PDT) MIME-Version: 1.0 References: <20230711062202.3542367-1-CoelacanthusHex@gmail.com> In-Reply-To: <20230711062202.3542367-1-CoelacanthusHex@gmail.com> From: Guo Ren Date: Wed, 12 Jul 2023 20:00:20 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] riscv: entry: set a0 prior to syscall_handler To: Celeste Liu Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Conor Dooley , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Felix Yan , Ruizhe Pan , Shiqi Zhang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, Jul 11, 2023 at 2:22=E2=80=AFAM Celeste Liu wrote: > > When we test seccomp with 6.4 kernel, we found errno has wrong value. > If we deny NETLINK_AUDIT with EAFNOSUPPORT, after f0bddf50586d, we will > get ENOSYS. We got same result with 9c2598d43510 ("riscv: entry: Save a0 > prior syscall_enter_from_user_mode()"). > > Compared with x86 and loongarch's implementation of this part of the > function, we think that regs->a0 =3D -ENOSYS should be advanced before > syscall_handler to fix this problem. We have written the following patch, > which can fix this problem after testing. But we don't know enough about > this part of the code to explain the root cause. Hope someone can find > a reasonable explanation. And we'd like to reword this commit message > according to the explanation in v2 > > Fixes: f0bddf50586d ("riscv: entry: Convert to generic entry") > Reported-by: Felix Yan > Co-developed-by: Ruizhe Pan > Signed-off-by: Ruizhe Pan > Co-developed-by: Shiqi Zhang > Signed-off-by: Shiqi Zhang > Signed-off-by: Celeste Liu > Tested-by: Felix Yan > --- > arch/riscv/kernel/traps.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index f910dfccbf5d2..ccadb5ffd063c 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -301,6 +301,7 @@ asmlinkage __visible __trap_section void do_trap_ecal= l_u(struct pt_regs *regs) > > regs->epc +=3D 4; > regs->orig_a0 =3D regs->a0; > + regs->a0 =3D -ENOSYS; Oh, no. You destroyed the a0 for syscall_handler, right? It's not reasonable. Let's see which syscall_handler needs a0=3D-ENOSYS. Could you give out more detail on your test case? > > riscv_v_vstate_discard(regs); > > @@ -308,8 +309,6 @@ asmlinkage __visible __trap_section void do_trap_ecal= l_u(struct pt_regs *regs) > > if (syscall < NR_syscalls) > syscall_handler(regs, syscall); > - else > - regs->a0 =3D -ENOSYS; > > syscall_exit_to_user_mode(regs); > } else { > -- > 2.41.0 > --=20 Best Regards Guo Ren