Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36404269rwd; Tue, 11 Jul 2023 00:02:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlGpdFYqOxGFJqBQMtSje11SPNsQjz1vXYxAAGOtVt8UtYq/n5bbuedSCu3ujKyDTl1xQQXE X-Received: by 2002:a2e:a40b:0:b0:2b6:df8a:d44b with SMTP id p11-20020a2ea40b000000b002b6df8ad44bmr11428143ljn.36.1689058939346; Tue, 11 Jul 2023 00:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689058939; cv=none; d=google.com; s=arc-20160816; b=cOPOwHDs1g1A43u3w5F85fYxCscAHiTQK1rpVN7+RAP3Tp32Sf0sEkKZbk7806GUT9 xXCSI7T9BWTReXzLRBI9dBRhz+MbOu4ruZBb27dLbxEF9c3KriTQUR6q6PzHbvB2Hi9R JvHHogCh6ROROUx5uXFpn571nkHQ0Spi2kXnKAsqJ7a3mWauPIqrdAvq8m7KiRjAXoJx TjB/RnloBwotd00nRb8rhL2UBzjQeLubVmBN8gOr3SGsQgp91bRD2P0+veGiKtpk1kJ1 Erv4+QXzW0aL1ieBN8ljuOVMpbREeQZzJx3sfL6IZhgxinbs5Mu8SGR9S3nuFt+C/aqv 0UNQ== 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=oAOhq9P07eLDplhtLTT1tcsIlFj5k7H1L3tXJlOgLCo=; fh=MAWe//ikZX7Eam7+Xv+1qPyMXSNj8kxbtepqFhIW6+Q=; b=oJXfkXe8vjj3YQe349pBGdpMhMPKWHrjqkL2QwDhrPnDaOTNxToDTtfXCwpN7qBPXv qY7qO9Ig9+sMhopP63XrXjZJCd57nWJq/p5Qk7LjgstXWcItuZznSamRTpAQ8nBOgm9N J72imDxwkIq1k313FMCELL+CvAz9ZsjP4p7RqErvaVl6/je/S6MTrp50CRspDE7JkVX5 rzepyyCoUWyU1AfZ8RRSHT3vNXImkMSHikMhDz2JC+P2o7OIOqYjVtdlK2R0mFkJax/1 Yk827s8rUjUUBDEs4nEo92ZfnTLVPDQZh3bRbJmcrb3FZj7RXbt8uvFsR64MDQEs8mOr kPNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="d/u6KhCW"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qx26-20020a170906fcda00b009925f1a32f8si1377104ejb.400.2023.07.11.00.01.54; Tue, 11 Jul 2023 00:02:19 -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=@gmail.com header.s=20221208 header.b="d/u6KhCW"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbjGKGWl (ORCPT + 99 others); Tue, 11 Jul 2023 02:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbjGKGWj (ORCPT ); Tue, 11 Jul 2023 02:22:39 -0400 Received: from mail-oa1-x41.google.com (mail-oa1-x41.google.com [IPv6:2001:4860:4864:20::41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CEBEE51 for ; Mon, 10 Jul 2023 23:22:38 -0700 (PDT) Received: by mail-oa1-x41.google.com with SMTP id 586e51a60fabf-1b3ca17f2a6so4368769fac.0 for ; Mon, 10 Jul 2023 23:22:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689056557; x=1691648557; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oAOhq9P07eLDplhtLTT1tcsIlFj5k7H1L3tXJlOgLCo=; b=d/u6KhCWa+HbTlst+lD44hjx/uPE6mkYk8t/U1cgZQ+rG8uR0vspAyOXTJytNDgvLu MKkpktIPWohmTYwzXkUYnCPq9FhZePT1kmmrcT2gnKLqlv2V9Xq92sAeI2OaW38wT/BT qCCcNEiv9xmMr8ANRmAwl8Li/Eqd/xvnolI9r64CY2cF9Rtsnc2zu7mE/7MvlMnXnz5J CMLUKgQJ/0H0z/OeOj3P9EEDixuEf/yupESXVfYvVJ1AXgTb+pqRAAvLjQNlEHplPnZa g3pPbSzasjHeQW1LmR/V2+J4sbYSnJW0+riWcIurE0vuIx8JLtXgYbkbRQNuoeGx8wDy B5gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689056557; x=1691648557; 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=oAOhq9P07eLDplhtLTT1tcsIlFj5k7H1L3tXJlOgLCo=; b=MVhe7EPNp+U+xKOUfYRCmDtpvoauw5fUusxmKyeukovcJY18RxhlGQkusm0aVKazYS jWz3q2bEwxdT66f2l/Nco3Bjv1kPNiGz7tc1sBrchhuTi2h5Xll2nocBeJoo0ARwCY0j NK7L3LZ5xaPlAikFcojBFvyEA2gZrNOg7m5XNmnptCwY1nl8jxjVD+LznQ9mZ8d69h/p Jtmp4LcgAalAcF0kGXkYXiUfVSzG0+OHEEY3qp43OvEOTKXa3P4oxKywNxCN1s3SvCPW o6d/Uemh8QOa42YCXXbRZ+TM8nwhxiwDCMBl291kgJKSQJTZDN7sJYJWXXMrp7Y0we5U jCdQ== X-Gm-Message-State: ABy/qLZXjLtbEFTsRBeKr1qJBD+QeMPQf8aBLpOcXyNI7xjFoiFJtERv g93Ak8i6LTW0kr2RCETcXIY= X-Received: by 2002:a05:6870:b48e:b0:1aa:f3:5b3b with SMTP id y14-20020a056870b48e00b001aa00f35b3bmr16428956oap.17.1689056557536; Mon, 10 Jul 2023 23:22:37 -0700 (PDT) Received: from localhost ([212.107.28.55]) by smtp.gmail.com with ESMTPSA id t3-20020a17090ae50300b0025edb720cc1sm968558pjy.22.2023.07.10.23.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 23:22:37 -0700 (PDT) From: Celeste Liu X-Google-Original-From: Celeste Liu To: Palmer Dabbelt , Paul Walmsley , Albert Ou , Guo Ren , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Conor Dooley , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Celeste Liu , Felix Yan , Ruizhe Pan , Shiqi Zhang Subject: [PATCH] riscv: entry: set a0 prior to syscall_handler Date: Tue, 11 Jul 2023 14:21:47 +0800 Message-ID: <20230711062202.3542367-1-CoelacanthusHex@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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 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 = -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_ecall_u(struct pt_regs *regs) regs->epc += 4; regs->orig_a0 = regs->a0; + regs->a0 = -ENOSYS; riscv_v_vstate_discard(regs); @@ -308,8 +309,6 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs) if (syscall < NR_syscalls) syscall_handler(regs, syscall); - else - regs->a0 = -ENOSYS; syscall_exit_to_user_mode(regs); } else { -- 2.41.0