From patchwork Fri Mar 29 17:12:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dmitry V. Levin" X-Patchwork-Id: 10877615 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 AB79715AC for ; Fri, 29 Mar 2019 17:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8714328A94 for ; Fri, 29 Mar 2019 17:12:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8519B28AC4; Fri, 29 Mar 2019 17:12:31 +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 C742A28ABF for ; Fri, 29 Mar 2019 17:12:30 +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:Message-ID:Subject:To:From :Date: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=d995xqr17ZSeYZDXZ2e4LswK7FUmdnakspAc6ggSGsI=; b=ci0sfUktXCwDJs ZSjQPrhOFoo0EGHncNkm/WSAdwqq/6VP9cslMwxoou3/7O3+W4qV9wm92usFnGIZ719sfzcCZq0O6 DPO9Tn+/ST2Hc0o+VlZwHCIUwV6porfcty+i6YyXyEVqi3laZXE+BMJrMqJmvldYj0MCVxqwxrahs XPN1WyzJJj36GNpfcrvjmDbp/JLijG9qputXpv4UPmGT8v1Ie3QTqH/k+y98gMwIA9aV+bd+LSWXD JC9ye1mzk8YKlbYvR0dSNjATdEj24GUXLC7nYgiVIRGdVANZFGpngYWOx0Bwz06zAd1TSDNwiZ1SE KDDAvkpSY3MbpIjWPXYQ==; 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 1h9v3L-0001T9-Pb; Fri, 29 Mar 2019 17:12:27 +0000 Received: from vmicros1.altlinux.org ([194.107.17.57]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9v3I-0001Sp-JL for linux-riscv@lists.infradead.org; Fri, 29 Mar 2019 17:12:26 +0000 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 4E95872CC64; Fri, 29 Mar 2019 20:12:21 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 264207CC74C; Fri, 29 Mar 2019 20:12:21 +0300 (MSK) Date: Fri, 29 Mar 2019 20:12:21 +0300 From: "Dmitry V. Levin" To: Palmer Dabbelt Subject: [PATCH] riscv: fix syscall_get_arguments() and syscall_set_arguments() Message-ID: <20190329171221.GA32456@altlinux.org> MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190329_101224_833330_6D5D4ADC X-CRM114-Status: UNSURE ( 7.74 ) X-CRM114-Notice: Please train this message. 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: Will Drewry , Kees Cook , linux-kernel@vger.kernel.org, Steven Rostedt , Andy Lutomirski , Ingo Molnar , linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Fixes: e2c0cdfba7f69 ("RISC-V: User-facing API") Cc: Steven Rostedt Cc: Ingo Molnar Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: linux-riscv@lists.infradead.org Cc: stable@vger.kernel.org # v4.15+ Signed-off-by: Dmitry V. Levin --- 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)