From patchwork Mon Apr 1 13:41:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 10879981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BD071669 for ; Mon, 1 Apr 2019 13:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E378A27480 for ; Mon, 1 Apr 2019 13:44:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D756A27F97; Mon, 1 Apr 2019 13:44:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4E5427480 for ; Mon, 1 Apr 2019 13:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:Subject:To:From :Date:Message-Id:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=QLtroJlU+kBw4S6gHy0SvlpeixWzbJOALZh2BfxGOZM=; b=GZI35C1e2mLitC QjLuNW7eLJMGE4XCvAB+8WCmNTV3p7+CAcfFyXfJsHgFipchRyAKpmys/DAYZAaESjrbpZOdZwvjc n/rYtOV0rv0dTVF/tY0Auii0PCnycenzhk+SdVNG0ii5y9nBWbe62SNpkuuC7ga5Pxx/S5AATBqnA VFZ56ko33av1wMmqgYBgveVzC7um48QKYaGH8c60Eh7QGLPMfQF7cjCPjeG1ysoTN8SfzuRSK7YBs nsxUdUQjtimBoYLd92XPmC1niqnT7qRl3VodqwwdCONrYCXgrBMV0TOY2/sfR30zuIqzX99JGFoJv QiyUk14cpuHU64fRBT1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAxEf-0008BQ-Nn; Mon, 01 Apr 2019 13:44:25 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAxEd-0008Ac-2f for linux-riscv@lists.infradead.org; Mon, 01 Apr 2019 13:44:24 +0000 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB49B2171F; Mon, 1 Apr 2019 13:44:21 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.92) (envelope-from ) id 1hAxEb-0003PV-2E; Mon, 01 Apr 2019 09:44:21 -0400 Message-Id: <20190401134420.958530155@goodmis.org> User-Agent: quilt/0.65 Date: Mon, 01 Apr 2019 09:41:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Subject: [PATCH 3/6 v3] riscv: Fix syscall_get_arguments() and syscall_set_arguments() References: <20190401134104.676620247@goodmis.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190401_064423_136268_99FAB3E4 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gustavo A. R. Silva" , Peter Zijlstra , Palmer Dabbelt , Dominik Brodowski , "Dmitry V. Levin" , "H. Peter Anvin" , linux-riscv@lists.infradead.org, Ingo Molnar , linux-arch@vger.kernel.org, x86@kernel.org, Ingo Molnar , Albert Ou , Kees Cook , Roland McGrath , Borislav Petkov , Andy Lutomirski , Thomas Gleixner , Will Drewry , Oleg Nesterov , Andy Lutomirski , "Eric W. Biederman" , Andrew Morton , Linus Torvalds Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Dmitry V. Levin" RISC-V syscall arguments are located in orig_a0,a1..a5 fields of struct pt_regs. Due to an off-by-one bug and a bug in pointer arithmetic syscall_get_arguments() was reading s3..s7 fields instead of a1..a5. Likewise, syscall_set_arguments() was writing s3..s7 fields instead of a1..a5. Link: http://lkml.kernel.org/r/20190329171221.GA32456@altlinux.org Fixes: e2c0cdfba7f69 ("RISC-V: User-facing API") Cc: Ingo Molnar Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: Palmer Dabbelt Cc: Albert Ou Cc: linux-riscv@lists.infradead.org Cc: stable@vger.kernel.org # v4.15+ Signed-off-by: Dmitry V. Levin Signed-off-by: Steven Rostedt (VMware) Acked-by: Palmer Dabbelt Acked-by: Palmer Dabbelt (for the RISC-V parts) --- arch/riscv/include/asm/syscall.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h index bba3da6ef157..6ea9e1804233 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -79,10 +79,11 @@ static inline void syscall_get_arguments(struct task_struct *task, if (i == 0) { args[0] = regs->orig_a0; args++; - i++; n--; + } else { + i--; } - memcpy(args, ®s->a1 + i * sizeof(regs->a1), n * sizeof(args[0])); + memcpy(args, ®s->a1 + i, n * sizeof(args[0])); } static inline void syscall_set_arguments(struct task_struct *task, @@ -94,10 +95,11 @@ static inline void syscall_set_arguments(struct task_struct *task, if (i == 0) { regs->orig_a0 = args[0]; args++; - i++; n--; - } - memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); + } else { + i--; + } + memcpy(®s->a1 + i, args, n * sizeof(regs->a1)); } static inline int syscall_get_arch(void)