Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2475726yba; Mon, 15 Apr 2019 12:25:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5CiKntl6ce+4Fqefn2h7UP4zCCIcW9qcxI2XKbkumkOAeFIdIm15pgfLfxvd/HqqMCfuH X-Received: by 2002:a17:902:2962:: with SMTP id g89mr28260868plb.264.1555356350623; Mon, 15 Apr 2019 12:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555356350; cv=none; d=google.com; s=arc-20160816; b=HQobz16OAUz5gjIlbptcciiOltd1ajWrh/aoa4HIssmcSbuUANDYJL3PGZk9vO557K jJLcIOWXxA7HQcy85V7J3PTMHIjF88Lu8zSyldVok1XjZwfXj1OsHNEZGpTo/KUOB05y D9uGsrQMak545Bowx8GCXSA0p5ftSSAJXGP7vPfrevLAn9+r3Dvk0m5y7VkP3sjRK9h9 0qqFoa0Ua5pa1GtDLQznObGqaD3yPLC3CjqRczp2uQApwDK2zd+oSHzW8iFRB+Z1mcXv +zrcjB4Lc3lDp9ERiXzt+4I8Udkv8gyzfYXE63RD5LTL65LNqzL0mnXlasAq/T5BRy8L jSMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KUnnhNuZroCxY0sL4bWPw8y7JP+FzDZExi5XLwJ5WFs=; b=wafElmDuAS9tMYZzcrBA8NG+JpWozcVcX86mAnSCPrGELJX4V9YmORCfFcvXEILAV7 qasDJm7HMug/Vqdyiul2PHHUO99i1lx8jvYZkxQpD2CAZ/pEbkfmpRz+RME48jvCRDV7 /f3FWcBt++rqbaFCoZXRJarBWHYXR6sIhqk1PIGbdl4Nw8urxje6wXCTaHolEvbhoc8M D0LunkVFCm79hRomOAIFwy4cweh5y7xT/fCF2McG49wR23h+SuXK3y9at0v6Fn8MnY3x yvc9eq+dzSUvmrExHq8hH9Ap1Z8atrZM+UGhEQz2cJk/R0aPuTcTdJjs1yyHRhxh4Qiq 1BXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XwKHungA; 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 b65si19941248pfg.120.2019.04.15.12.25.34; Mon, 15 Apr 2019 12:25:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=XwKHungA; 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 S1730273AbfDOTHm (ORCPT + 99 others); Mon, 15 Apr 2019 15:07:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728553AbfDOTHj (ORCPT ); Mon, 15 Apr 2019 15:07:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B77A7218D3; Mon, 15 Apr 2019 19:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355258; bh=NSit78T3Vqt1LsLyM32f+ZxYp6oa2w0kebm1Ee3VE4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XwKHungADuyCoba5gn6lGjxdg1miHCO6Fy+Zx/kplS9A2UYi9KElR8ngMlX7cxfnk mThX+TwsekFYlGSGfVwF9hdv+BLoM1PkP4kTAjdTpt4x28XgJaT8jGyhUiB4KOHcCl 3wjoaRt2ZravW1uzgejBSFI2d+S/+cyzKIosi/wE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Kees Cook , Andy Lutomirski , Will Drewry , Albert Ou , linux-riscv@lists.infradead.org, Palmer Dabbelt , "Dmitry V. Levin" , "Steven Rostedt (VMware)" Subject: [PATCH 4.19 070/101] riscv: Fix syscall_get_arguments() and syscall_set_arguments() Date: Mon, 15 Apr 2019 20:59:08 +0200 Message-Id: <20190415183744.172230767@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry V. Levin commit 10a16997db3d99fc02c026cf2c6e6c670acafab0 upstream. 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: Albert Ou Cc: linux-riscv@lists.infradead.org Cc: stable@vger.kernel.org # v4.15+ Acked-by: Palmer Dabbelt Signed-off-by: Dmitry V. Levin Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- arch/riscv/include/asm/syscall.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -78,10 +78,11 @@ static inline void syscall_get_arguments 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, @@ -93,10 +94,11 @@ static inline void syscall_set_arguments 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)); } #endif /* _ASM_RISCV_SYSCALL_H */