Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1114734imm; Fri, 29 Jun 2018 11:37:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK+V4/eeqBKpoHHO1X2yj1H37B83BgxY5rmWJtjTsSLI31IDw+n50TGH3gRyh3CNGwbJqP7 X-Received: by 2002:a65:42c3:: with SMTP id l3-v6mr12990150pgp.398.1530297470479; Fri, 29 Jun 2018 11:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530297470; cv=none; d=google.com; s=arc-20160816; b=MDeYx+FdX/1vG4qtACF0D45Ocs7pPfL8hXv8trKIxyaxb9YMGKtLEbXi6IM6a1NM4J Fa+WjE8Mt67/qjbJycOR2fB2xKcTLLY26AjhjVSmfoneg5wCgmLOD3m+84iyEDBavslN bi91Sc0/8mZH/3IS7tKjKEmRK8FHiYw6m05892LNgAQSCx6rLzTvmlu9uYGWfmIFr9P1 x6tYTt05M03cHuvxgXMB3VXiV1heymv/tUEP/UfN/YZlA8EqSokkFjxH9J2utRw3YF9u C94KpIjsJZUyPMKfoy0WPuF5BnXutjxZ2MfBlrQL+mFLvf6vpRG6WcbzjSKloSJNQTl0 pkLg== 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=M5i8WOF6+1fMnSeFc30wcMiksgX+5/LYFYoUAY6C/fo=; b=mfvVfQOdF/Rzyhllj/tomkjsVQ9tYrv2Bi6ICm3aX+CbuDGLKTXsY4k4slSyl2nAI0 CKOFDJARW02lcJ1g95IYTeDWxYDUEMmEQVCQlZbCrIaHbWCAy/JA54v3ceIXCFrDI65x lBZf2F4x++GjT5DzuoGGY006bQ50NjNGmVtl54sySlCHozD5g3RXKz0rtCFQpVJgzFiJ FL1v/sLxPzpgzebe9qb0ATPTbKlr/wyayTqIoX/hkLCH+mJPhzcTdAeRObIsOqSwxYap cm4brpBBLGTlvd/X6KrBWgZHHaVlUx8+x9/rrjWHw3oczeunBW+9+pMLJ3ZEdbdsPudg Z/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=b3Oxpr4F; 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 q13-v6si9831730pll.72.2018.06.29.11.37.36; Fri, 29 Jun 2018 11:37: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=@efficios.com header.s=default header.b=b3Oxpr4F; 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 S936074AbeF2QHQ (ORCPT + 99 others); Fri, 29 Jun 2018 12:07:16 -0400 Received: from mail.efficios.com ([167.114.142.138]:34608 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933911AbeF2QHO (ORCPT ); Fri, 29 Jun 2018 12:07:14 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 6947B22EF00; Fri, 29 Jun 2018 12:07:13 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id Oedmk33_GCpB; Fri, 29 Jun 2018 12:07:12 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id D5E7A22EEFA; Fri, 29 Jun 2018 12:07:12 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com D5E7A22EEFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1530288432; bh=M5i8WOF6+1fMnSeFc30wcMiksgX+5/LYFYoUAY6C/fo=; h=Date:From:To:Message-ID:MIME-Version; b=b3Oxpr4FxOCh03nuKUMk4boZJlvW4sld76/tVGnJGPqueuIkajKvut2wFYed/lpzD 0OTPLD9BJFIffEINJfu6g78aD4qui2rQ8UQVdPJeMZF6oePAHRkwkTTIClso5m/FNO Y2VqAVoJAhQ+adRJ5Ej/aBpVQyC6WyXV8rKRM2YZkEOW5m+e11zk+mvDIAe9lnawkn 4UFLOJ8kKkAE67NXTZBgpwOyzwXaZfknahEmKSJPdldLLnJbBV9bnfNbZC5bFUOTua uPRiJ3UeCB2f7OgrriJT1e8kxrcETFIQJwVwzqnTnMMQz69uTRpXK/2+2cbGacGlh/ GHHnwbb+qSVDg== 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 W_4PiZ2fArJj; Fri, 29 Jun 2018 12:07:12 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id B9CF922EEE8; Fri, 29 Jun 2018 12:07:12 -0400 (EDT) Date: Fri, 29 Jun 2018 12:07:12 -0400 (EDT) From: Mathieu Desnoyers To: Linus Torvalds Cc: Andy Lutomirski , Andy Lutomirski , Thomas Gleixner , linux-kernel , linux-api , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Dave Watson , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H. Peter Anvin" , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes Message-ID: <247789350.9741.1530288432573.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20180628162359.9054-1-mathieu.desnoyers@efficios.com> <9200ED2A-AE4B-4094-81C9-E92240B4840F@amacapital.net> <1706339668.9644.1530281144560.JavaMail.zimbra@efficios.com> <729451355.9702.1530284622326.JavaMail.zimbra@efficios.com> Subject: Re: [RFC PATCH for 4.18 1/2] rseq: validate rseq_cs fields are < TASK_SIZE 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: validate rseq_cs fields are < TASK_SIZE Thread-Index: WiucE5TyA/5qz+mgdMTb6RCJOC0x2Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jun 29, 2018, at 11:54 AM, Linus Torvalds torvalds@linux-foundation.org wrote: > On Fri, Jun 29, 2018 at 8:27 AM Linus Torvalds > wrote: >> >> You simply can't have it both ways. > > Put another way. > > This is ok in the native path: > > if ((unsigned long) rseq_cs->abort_ip != rseq_cs->abort_ip) > return -EINVAL; > > because it's checking that the value fits in the native register size > (and it also ends up being a no-op if the native size is the same size > as abort_ip). > > And this is very much ok in a compat syscall: > > if (rseq_cs->abort_ip & ~(unsigned long)-1u) > return -EINVAL; > > because it's checking that the pointer doesn't have (invalid in > compat) high bits set. > > But it is NOT OK to say "the rseq system call doesn't have any compat > syscall, but we'll do that compat check in the native case, because we > worry about compat issues". > > See what I'm saying? Either you worry about compat issues (and have a > compat syscall), or you don't. > > The whole "let's not do a compat syscall, but then check compat issues > at run-time in the native system call because compat processes will > use it" is braindamage. This code is not invoked from syscalls, but rather on return from interrupt/trap after a preemption. So a compat system call does not solve it. Unless we grab the "compat" state on rseq registration, save it in a rseq_compat flag within the task struct, and then use it on return from interrupt/trap/syscall. Otherwise we need to figure out whether we are dealing with a compat task when interrupt and trap context return to userspace. We had is_compat_task() for that before, but now it has vanished from x86. We could use user_64bit_mode(struct pt_regs *) on x86, but it does not exist on other architectures. One possibility is to introduce a new API that calls user_64bit_mode() on x86, and is_compat_task() on other archs. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com