Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp25463imm; Thu, 28 Jun 2018 14:09:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpelKpd0kJmrhcBvuCKLVg1pY6wpfZptSKLurXKfrY6AcoysDma0ShqgQd3BnWpf1KYo/5ih X-Received: by 2002:aa7:808f:: with SMTP id v15-v6mr11716589pff.38.1530220168285; Thu, 28 Jun 2018 14:09:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530220168; cv=none; d=google.com; s=arc-20160816; b=YE2TLFBQ2ri+TsAX8BEG5VM9Gu8mYoaaQF1m6uq1bPMkHTIklWfX/6uQ8z/Aly5UQ+ Y1cCLVdKIwgvrz0SIPrJDL8odt6bWg6kt+XvCbY5WYjLvxwsPnzVBhOBnD++KpQ5UQpT /iRS54yZpNHC17b3bI6MTGgDUVs5uOsADJtm/Gc2F7LjrxJUNEdX60kIz7tXLqwfgD17 2fqOLyFsZsoTX6jJioE2DMglXFNhBrxoeGfDeqYOX6jbqn6x5YFVod7ZKNJDmgK9JE0I IhK5eGk/JKQkH6m6pegiaqNOPBw5ofJCLTOz2o26JnvQy2O0DHCAwjMOROurkuZX4zOh 8law== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter :arc-authentication-results; bh=IcQd3NTPIgp6VsYT2ufu57V1GnAc6U8MoK5VS3Hu+K8=; b=dqSxpMgIi9ooyVFl1A9C/GUAlZUuZze7R3Gi3v27daSHuT2a14wcgglC2B9za8lmzg TLfdntVCjs/7pEpvOl43CA31MWuidMzhNjLNV/QCg2Gq6Y+zc/5xsdZ53louRvYC0oz2 IQTQQL3veUetRoli0znDFFx4kPRFyTBlh++l2JUIFvbG8b2IRYuAAHOkhDbPiWLKE3My rHKJasSroE/pbrOnpbc/zb/ygaIesgnnWiGNrP1LrxiFzWGnBlMG4KIu1TVgxrbo1Qce K5Kj/meb5Jnz+Mwgzok6zlNiwC5Ty+Vg8Fn/Wn20WBUXnOBY9ppXaY9oHiUXZRxLG1Hd h8cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=pEdx7QFt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12-v6si7391812plk.48.2018.06.28.14.09.03; Thu, 28 Jun 2018 14:09:28 -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=@efficios.com header.s=default header.b=pEdx7QFt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935591AbeF1Uz7 (ORCPT + 99 others); Thu, 28 Jun 2018 16:55:59 -0400 Received: from mail.efficios.com ([167.114.142.138]:50064 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934003AbeF1Uz4 (ORCPT ); Thu, 28 Jun 2018 16:55:56 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 2DF6A22EA22; Thu, 28 Jun 2018 16:55:56 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id QiA4YQtKdm_Q; Thu, 28 Jun 2018 16:55:55 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 69C6522EA17; Thu, 28 Jun 2018 16:55:55 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 69C6522EA17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1530219355; bh=IcQd3NTPIgp6VsYT2ufu57V1GnAc6U8MoK5VS3Hu+K8=; h=Date:From:To:Message-ID:MIME-Version; b=pEdx7QFtZ4V81u+fup6R3isYTt9/PAO7ZAg8Lakl/ibFrncJfLBYh+SavWjobGuSM jwlkDfBzUlgl68hOLDVlH8T0c7Syi16ld5Xgcut15NgSgpjnv7ySkXrLVVG4zM05SB z2w9yDFqXR3cuWsMDOEH2xSrfQ8MJJaY/40fd/XVXS4Av/OYo81WnX73JDEh60uNF1 fZThUno04qsy+IDf48GyJu0CbLs8vuqGrvLIvDpW6tdy9V1s6WQ/je4WcA2syIlgAS 2VfjeiChREq9UHypZgs5bt5OxyFNdsq4oMJlaimz8fL9/UMPA8d6v4MddbsQx4CFMU BwwwDoojWA/Mw== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id QJQWKQx0Y4hl; Thu, 28 Jun 2018 16:55:55 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 4BF6622EA0C; Thu, 28 Jun 2018 16:55:55 -0400 (EDT) Date: Thu, 28 Jun 2018 16:55:55 -0400 (EDT) From: Mathieu Desnoyers To: Will Deacon Cc: Thomas Gleixner , linux-kernel , linux-api , 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 , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Michael Kerrisk , Joel Fernandes Message-ID: <145668759.9406.1530219355192.JavaMail.zimbra@efficios.com> In-Reply-To: <20180628165348.GE10751@arm.com> References: <20180628162359.9054-1-mathieu.desnoyers@efficios.com> <20180628162359.9054-2-mathieu.desnoyers@efficios.com> <20180628165348.GE10751@arm.com> Subject: Re: [RFC PATCH for 4.18 2/2] rseq: check that rseq->rseq_cs padding is zero MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.8_GA_2096 (ZimbraWebClient - FF52 (Linux)/8.8.8_GA_1703) Thread-Topic: rseq: check that rseq->rseq_cs padding is zero Thread-Index: 0yd5tDgqkI8JsxsjRwSMAAu3hkRTxw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jun 28, 2018, at 12:53 PM, Will Deacon will.deacon@arm.com wrote: > 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? With a 64-bit kernel, we end up in the #else, which means check_rseq_cs_padding() always returns 0. On that 64-bit kernel, all 64 bits of rseq->rseq_cs are read, including the padding. Therefore, all those bits are contained in the pointer passed as argument to copy_from_user(), which will cause copy_from_user() to accurately fail on an invalid user-space address. Therefore, 64-bit kernels already check those padding bits by means of trying to use that pointer to access user-space data with copy_from_user, which does an access_ok check. So both 32-bit and 64-bit kernels will end up killing the process with segmentation fault if a 32-bit userland populates those padding bits with anything other than 0. Does it seem acceptable ? Thanks, Mathieu > > Will -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com