Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp504513imm; Mon, 2 Jul 2018 16:01:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfwh6j0w/QDCX7CZcwiVZrAXTlULW316YIdIxnLBajTJLrfWJb7G0QH+P14Zle2Jz3Odfvu X-Received: by 2002:a63:4857:: with SMTP id x23-v6mr5144858pgk.30.1530572500380; Mon, 02 Jul 2018 16:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530572500; cv=none; d=google.com; s=arc-20160816; b=UIVYjSwAE30saNeGCdAdTf+PI+xRsKOojkz6NHVd9JyDb0vyOGN9MyQVe3/pgXrrj/ F9QOvCoAv+z4vcSA8bSx3waU6jMyY9jRkGazapiu+BcgZTQNpBovW40u3eKpvg/yTOJy NvTqK3//sdvtb7KkzI++YpLIEnbO9+0+nWXM8U2egx6WMy3v3tB0a7vagUGqCMzof+2J Fcg2KXc9XNqdHhHsQ5VBvtlOUO+2m+PtkGvwZ6gdeTdZsxh8aKB7To6x5bpAdDMoBBLH AfyxhYUu3SeRly+4FII788eejvgcD7lQnbSwaIOkh6HPx/uIuESUzSXQkok9u6O6MTS3 ke5A== 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=751AlYfhH14RHiUOzu/+/a7kvkFwuBpEIBKW6rX8qdQ=; b=U6pF8HeMLb5+KPjFiI6Fc1vGvLw3fIlj5AMMjZVt2N/wYSVgv/V7SyJAYXX6m0tAj3 MOldfm+224ctPlBQ3t/M8jgeoSVrHCBrVZIk7+oZgtwPSpGe0tk9cbJSAcrSFsLOro8E uQpWemF2dDDgBjOFJ75PmO5bPlakNr4oNIjugyay9SJPkvHon9zv9L9z0ah0liZcA1ZK TfXNJrZh/2QARTPhVpIusQ1LNxLe+jUOBqRwUsbfcqqJ3LHibNBUbxbjnhEkAus2UdQF A3X9MKSFjMP5lIonzRF18sQcXk9s8JP756oqoMEMLVXzP5ZLVAtYOMbtAOGxA9NYq/8W kJ+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=XLYrRj1R; 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 w11-v6si14884683pge.422.2018.07.02.16.01.25; Mon, 02 Jul 2018 16:01:40 -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=XLYrRj1R; 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 S932838AbeGBXAX (ORCPT + 99 others); Mon, 2 Jul 2018 19:00:23 -0400 Received: from mail.efficios.com ([167.114.142.138]:47008 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932213AbeGBXAU (ORCPT ); Mon, 2 Jul 2018 19:00:20 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id BC61222F860; Mon, 2 Jul 2018 19:00:19 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id hSvqn4siwX1t; Mon, 2 Jul 2018 19:00:19 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 2B36F22F85D; Mon, 2 Jul 2018 19:00:19 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 2B36F22F85D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1530572419; bh=751AlYfhH14RHiUOzu/+/a7kvkFwuBpEIBKW6rX8qdQ=; h=Date:From:To:Message-ID:MIME-Version; b=XLYrRj1RdUNKfCoiDrSqbZh3Iqd4XVl2kh5Ac9lswJwVtuws67EUmJ8LcFfP08ccZ enUijtCU/gv6+Te0TFx454WOU8T8NbVRELSLDmJTIQGDzHXjuKaZTKM1iHS4xROam0 XsPxiaGMCGSAnibW7IaA2H7jJjIYx19ubgtUHVkYmmTSF9OfK+OKZaqtasWEhBKVgP VXKMJKmZaJXjGxonPjPF1Mv/95A/RAbIXWMYfP2b/JU023hD3IzXWpe6EMJNuSkaD1 kpAoXghjRc8PieZXeG6gXOCwiRFUxUbNwJY9g1UEvY1qQWEw4sLcJU1ASaE9zrbxnZ 5A4gaXxjt8jPQ== 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 0aYL-8Bt_eyX; Mon, 2 Jul 2018 19:00:19 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 0C5EA22F856; Mon, 2 Jul 2018 19:00:19 -0400 (EDT) Date: Mon, 2 Jul 2018 19:00:18 -0400 (EDT) From: Mathieu Desnoyers To: Linus Torvalds 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 , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes Message-ID: <415287289.10831.1530572418907.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20180702223143.4663-1-mathieu.desnoyers@efficios.com> Subject: Re: [RFC PATCH for 4.18] rseq: use __u64 for rseq_cs fields, validate user inputs 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: use __u64 for rseq_cs fields, validate user inputs Thread-Index: v1eEGYKuadK8hiZjpAVSo1GQwiHEtQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jul 2, 2018, at 6:45 PM, Linus Torvalds torvalds@linux-foundation.org wrote: > On Mon, Jul 2, 2018 at 3:31 PM Mathieu Desnoyers > wrote: >> >> Change the rseq ABI so rseq_cs start_ip, post_commit_offset and abort_ip >> fields are seen as 64-bit fields by both 32-bit and 64-bit kernels rather >> that ignoring the 32 upper bits on 32-bit kernels. This ensures we have a >> consistent behavior for a 32-bit binary executed on 32-bit kernels and in >> compat mode on 64-bit kernels. > > Actually, now that I see this again, I react to: > > >> +static int check_rseq_cs_padding(struct task_struct *t) >> +{ >> + u32 pad; >> + int ret; >> + >> + ret = __get_user(pad, &t->rseq->rseq_cs_padding); >> + if (ret) >> + return ret; >> + if (pad) >> + return -EINVAL; >> + return 0; >> +} > > This is all wrong. > > Just make "rseq_cs" be an __u64" too. That will clean up everything, > and user space will have a much easier time filling it in too, since > it's just one field. Instead of having to remember about the "let's > fill in padding for 32-bit cases". > > Then the rseq_get_rseq_cs() will be > > __u64 rseq_cs; > > ret = get_user(rseq_cs, &t->rseq->rseq_cs); > if (ret) > return ret; > ptr = (void *)rseq_cs; > if (rseq_cs != (unsigned long)ptr) > return -EINVAL; > > and it's all good, no #ifdef's etc needed. > > Hmm? Unfortunately, that rseq->rseq_cs field needs to be updated by user-space with single-copy atomicity. Therefore, we want 32-bit user-space to initialize the padding with 0, and only update the low bits with single-copy atomicity. > > Sorry for the bike-shedding, but this is now the last remaining user > of that LINUX_FIELD_u32_u64, so let's just get rid of it entirely, ok? > > Then we can also get rid of that silly uapi/linux/types_32_64.h header > file entirely. > > That would be *lovely*. Simpler code, simpler and less error-prone > interfaces, and one less specialized header file. We can easily switch from LINUX_FIELD_u32_u64 to __u64 for fields within struct rseq_cs because we have no requirement on update single-copy atomicity. However, this is not true for the rseq->rseq_cs pointer. Thoughts ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com