Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7977781imm; Thu, 28 Jun 2018 12:25:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK9t6RHeO9xx/7yeNfCjHkEsUKzF/qUw+zhRPIxwcRHANWEyQ7k++Z2lBTnqC/xH5nnHZ53 X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr11949638plu.22.1530213916992; Thu, 28 Jun 2018 12:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530213916; cv=none; d=google.com; s=arc-20160816; b=FI+1miDpBM2GeDWhZl9xAx1lICjHfB7Gej1sXP2kbnOj14b/bpWQVljz3GWsvR70j5 NGuwdoCL8D+6Qxb7l4jjb/0p65IIvYoRaaUo1SpYloFn9pT21+5An2Gv95B9+uaJ4oXF erMUN0ITb8+vzeXmyuO9HDV7fgUjkOdmDACbKKmaJ5KNpFwn31JeIr/ffBI77qI5GlgN 7ZDA62Pj3dPp0Atdah1YUDCgpBZDiQrGInH39uXaTW9g+9JvThBd7+gluvYrIuIvZBwu CFFUaSOS+Vxcb1lSFjexlpvg+oUJcdbRibKZvIF7xVGZHo/HXrQvyWpiXMh3TtC2r/l2 o4tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=4i66Z1Py1uyMNDKRoLkaVmsy9uSCS8sByZAWxBGgFQI=; b=z+8IJy1kGMCY6ywukVjdtb8W+tSlqm6VIycOT4jS9mXK6qcebXSybcuMWtm3EE/J9q gkfR8n8teOf0JO9w+NdPtiaURuXAN4F+t5LZGv0alBXqIpw+mnaXTT77hISjsPfXq1xS 6mnOvED5LWX5VxJ/ClYB4EqgxAmi4IcPvugBZwL3WmnkNNHQKaIBpa8EyCBCp6BoRUMn j+wjPxJTQaHTogHoGTNVue3POvs2Z7hKh+gpNPbOw0DiYDlwT6ocZZ/qV+rsbe1Uiult 7cGvp3PRKCVhA4AnekMcdIwU5N/qb8/ziNahy2vU5vXx0CGPTJPueeDFJh6KB+hIGFGp gVmQ== 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 7-v6si7573901pll.212.2018.06.28.12.24.32; Thu, 28 Jun 2018 12:25:16 -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 S935749AbeF1QxN (ORCPT + 99 others); Thu, 28 Jun 2018 12:53:13 -0400 Received: from foss.arm.com ([217.140.101.70]:50482 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753501AbeF1QxL (ORCPT ); Thu, 28 Jun 2018 12:53:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A17DC18A; Thu, 28 Jun 2018 09:53:10 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 718FF3F318; Thu, 28 Jun 2018 09:53:10 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 96D2A1AE540D; Thu, 28 Jun 2018 17:53:48 +0100 (BST) Date: Thu, 28 Jun 2018 17:53:48 +0100 From: Will Deacon To: Mathieu Desnoyers Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Peter Zijlstra , "Paul E . McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H . Peter Anvin" , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Michael Kerrisk , Joel Fernandes Subject: Re: [RFC PATCH for 4.18 2/2] rseq: check that rseq->rseq_cs padding is zero Message-ID: <20180628165348.GE10751@arm.com> References: <20180628162359.9054-1-mathieu.desnoyers@efficios.com> <20180628162359.9054-2-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180628162359.9054-2-mathieu.desnoyers@efficios.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On Thu, Jun 28, 2018 at 12:23:59PM -0400, Mathieu Desnoyers wrote: > On 32-bit kernels, the rseq->rseq_cs_padding field is never read by the > kernel. However, 64-bit kernels dealing with 32-bit compat tasks read the > full 64-bit in its entirety, and terminates the offending process with > a segmentation fault if the upper 32 bits are set due to failure of > copy_from_user(). > > Ensure that both 32-bit and 64-bit kernels dealing with 32-bit tasks end > up terminating offending tasks with a segmentation fault if the upper > 32-bit padding bits (rseq->rseq_cs_padding) are set by adding an explicit > check that padding is zero on 32-bit kernels. > > Signed-off-by: Mathieu Desnoyers > CC: "Paul E. McKenney" > CC: Peter Zijlstra > CC: Paul Turner > CC: Thomas Gleixner > CC: Andy Lutomirski > CC: Andi Kleen > CC: Dave Watson > CC: Chris Lameter > CC: Ingo Molnar > CC: "H. Peter Anvin" > CC: Ben Maurer > CC: Steven Rostedt > CC: Josh Triplett > CC: Linus Torvalds > CC: Andrew Morton > CC: Russell King > CC: Catalin Marinas > CC: Will Deacon > CC: Michael Kerrisk > CC: Boqun Feng > CC: linux-api@vger.kernel.org > --- > kernel/rseq.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/kernel/rseq.c b/kernel/rseq.c > index 4ba582046fcd..b038f35a60d6 100644 > --- a/kernel/rseq.c > +++ b/kernel/rseq.c > @@ -112,6 +112,29 @@ static int rseq_reset_rseq_cpu_id(struct task_struct *t) > return 0; > } > > +#ifndef __LP64__ > +/* > + * Ensure that padding is zero. > + */ > +static int check_rseq_cs_padding(struct task_struct *t) > +{ > + unsigned long pad; > + int ret; > + > + ret = __get_user(pad, &t->rseq->rseq_cs_padding); > + if (ret) > + return ret; > + if (pad) > + return -EFAULT; > + return 0; > +} > +#else > +static int check_rseq_cs_padding(struct task_struct *t) > +{ > + return 0; > +} > +#endif I'm still not sure how this works with a 64-bit kernel and a compat (32-bit) task. The check_rseq_cs_padding() will return 0 regardless of the upper bits of the rseq_cs field, whereas a native 32-bit kernel would actually go and check them. What am I missing here? Will