Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp300554yba; Mon, 1 Apr 2019 06:45:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTh+IPNTH3wBcoRMwmbRJeURl6w27Kxuw1A60MeqIqX/LvL96Jmy5+cQBmg9qAgUwQjRbb X-Received: by 2002:a17:902:123:: with SMTP id 32mr63796707plb.187.1554126346172; Mon, 01 Apr 2019 06:45:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554126346; cv=none; d=google.com; s=arc-20160816; b=UtquVyF+CuFD/nRto+5TYpK8AdLpy0eE1Pp2PMgSVqrX7fYdy8bD7llk/HkV7EFUuA kZ9g5nu8kvZ6SZ4tZJFgazJyx6yeyPOZsOATjwJzpMVfQNb8Nluc1Y4gdRdCQ22eq+BK Zh3MnpqM3oHAD1cE0udBsilBBgmqJZhEGmo5HoOayFZlJV8UfE891hxHnCt5baNQbC/y 7zjOqtj/xUHXrrgkD4zy8l7lVhXrDBYjv193vtIxUf6tFo2ZLgr3Q1wkS6dzCviv8Vwr 3q5vX02XqQkiPtlE+Y7Va3Yao4DlX4qrG9seCEQPfbFlNIDVi5uYdebGWWyVujH0pyHd Z4iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=uWqZ9+X1XtlQdsV2udZfPPz0RHm0q4S8XOyQEI65dhM=; b=mn6dnkytx6RT0GryC3NRFu6UP+MieuyGQMC8NxcyVLPtizgyTloKL5E8U32YN31BBz PJYwyVxAhQp/z2kL6ZS3spRg05jLIZ8xpYV/sfSSRs7RjJ8CM/g5ClfKoh1t10WrV0lL GfUDkzvhI/ACPWUNpkHk4rqrGwVYhQ+Ys5re9XWXpNuhxbE+HBYrxJM0vMq9tcBfwaa+ pge9nwzbvgA4Kx60f+UIKzB0uBVhLnKEk53SlO6FuODfXrPH6Jipd8lKQ6eQV3WmFTez FWY9YeCjvKIJ0EDTiuOmunDDl7jHvsS0PSyeqwjU03KIEPuzSlhr9TNoYlMd7NxwN2sx p16w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89si8776021pfs.243.2019.04.01.06.45.30; Mon, 01 Apr 2019 06:45:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728654AbfDANoY (ORCPT + 99 others); Mon, 1 Apr 2019 09:44:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726945AbfDANoW (ORCPT ); Mon, 1 Apr 2019 09:44:22 -0400 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 Cc: Linus Torvalds , Ingo Molnar , Andrew Morton , Andy Lutomirski , Roland McGrath , Oleg Nesterov , linux-arch@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , "Gustavo A. R. Silva" , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Dominik Brodowski , Andy Lutomirski , Kees Cook , "Eric W. Biederman" , "Dmitry V. Levin" , Palmer Dabbelt , Will Drewry , Albert Ou , linux-riscv@lists.infradead.org Subject: [PATCH 3/6 v3] riscv: Fix syscall_get_arguments() and syscall_set_arguments() References: <20190401134104.676620247@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) --- 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) -- 2.20.1