Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp416283imm; Thu, 28 Jun 2018 23:27:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpep0pvGSLZQse/yyJVf4IwN/fkYowg7N9zTpxBG7pxEgGQOFqmrgZyG5XgBRbecfDY935Om X-Received: by 2002:a62:3b03:: with SMTP id i3-v6mr5375771pfa.197.1530253676399; Thu, 28 Jun 2018 23:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530253676; cv=none; d=google.com; s=arc-20160816; b=DkCx9DQ36bQkScuj5PY5rX3m/6KHaRXI+Xu2rWjX0X6RBBRivx5rCmtYMNRWhx2WCf hgE8upFxSAL303qLFU5XFYxEb/D6OO9LzjnCzCIF8Tp52M7HqlyBKO5DRZwlNLMwY2FO UKZeljmrIHqx1O2yi3kphVJf28joqdfkL82gqiaBigDfpWXtPJZAQ4rEA+1rxCc/FHtm FvpWusXjLhqsVK9IgJUZ5Q1WtwMW4/xdx0bsV8QQnmDr1Gq8JmvhxXpe67Ix3Vex+Om8 Mpvqr4nVHo//DI+NQ/56I4R20cn3hdVTHO119KcGXf28SYZdalkOeoxEoqUbxqa50xM6 spqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=YmtcPe3POM4/B55oriS5EVVrtmEG7VWAtVwzfo64U4I=; b=FZscpdFF5TSmG+K35nASMzcv5vbldSVuk7MZYqYjgAdp26GK4NautW2GLJqRQSfY9W laKXeZVlM7pwvUcetI9I1LiIcpIDzg+aLos8NKhJ4T8aZgUuQrM2/674LM/r0v5tULJ9 lsMyAnO7W8bw/3xujswFQUKD526kXf4CarR0nDnleTZsfB6Zm+TXVBSfqUM4knUnQXv4 ZOucTiSICXfhcxUDP/AJgA+sFFK9YE2gm7AIuIVlmromkeper3x2h6OL+2RgZExy2w0Z 8AiDYXmcAhgWZuCRWkO0/3N/dASBD3+Hk7iaEfFwuB++Ez9HVqzjfrVfbEshgUmIagoH Igow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NhaSoE5a; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g80-v6si3792608pfk.53.2018.06.28.23.27.42; Thu, 28 Jun 2018 23:27:56 -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=NhaSoE5a; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753857AbeF1XaU (ORCPT + 99 others); Thu, 28 Jun 2018 19:30:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:56404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753224AbeF1XaS (ORCPT ); Thu, 28 Jun 2018 19:30:18 -0400 Received: from mail-wr0-f170.google.com (mail-wr0-f170.google.com [209.85.128.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 584AB27A64 for ; Thu, 28 Jun 2018 23:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1530228617; bh=UHPcfjjF3HVJ2SeYOqaQCEBTsZgrZ/bh5l6vCRIibYI=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=NhaSoE5aSX8cBEtSH2PPdzZKnMOCpk+o3w6/RuqZSc7uV2Pk8CfZP77Gw51eFryWT XVfpzN9uxfmPtOEi0qe2lhIQZsbJUcO/izfmplfPQxPOxmkaMv7ZvZHNa8VJvlj8TG cOZPi5Pki5XfTUei+z7YSTtUa7urP9tGvkjaiYbw= Received: by mail-wr0-f170.google.com with SMTP id c5-v6so7066064wrs.10 for ; Thu, 28 Jun 2018 16:30:17 -0700 (PDT) X-Gm-Message-State: APt69E3IO9i5drm8VHrVo5CUb4Jedm5Fjx5e6szwF/iPnucWKivBFErh yS4V8oY1BJr9akSUVKFpBiq+QUd1VTzNfipZ8irWTQ== X-Received: by 2002:adf:b445:: with SMTP id v5-v6mr10072993wrd.67.1530228615843; Thu, 28 Jun 2018 16:30:15 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:7e92:0:0:0:0:0 with HTTP; Thu, 28 Jun 2018 16:29:55 -0700 (PDT) In-Reply-To: References: <20180628162359.9054-1-mathieu.desnoyers@efficios.com> From: Andy Lutomirski Date: Thu, 28 Jun 2018 16:29:55 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH for 4.18 1/2] rseq: validate rseq_cs fields are < TASK_SIZE To: Linus Torvalds Cc: Andrew Lutomirski , Mathieu Desnoyers , Thomas Gleixner , Linux Kernel Mailing List , Linux API , Peter Zijlstra , Paul McKenney , Boqun Feng , Dave Watson , Paul Turner , Andrew Morton , Russell King - ARM Linux , Ingo Molnar , Peter Anvin , Andi Kleen , Christoph Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 28, 2018 at 2:22 PM, Linus Torvalds wrote: > On Thu, Jun 28, 2018 at 1:23 PM Andy Lutomirski wrote: >> >> This is okay with me for a fix outside the merge window. Can you do a >> followup for the next merge window that fixes it better, though? In >> particular, TASK_SIZE is generally garbage. I think a better fix >> would be something like adding a new arch-overridable helper like: >> >> static inline unsigned long current_max_user_addr(void) { return TASK_SIZE; } > > We already have that. It's called "user_addr_max()". Nah, that one is more or less equivalent to TASK_SIZE_MAX, except that it's different if set_fs() is used. > > It's the limit we use for user accesses. > > That said, I don't see why we should even check the IP. It's not like > that's done by signal handling either. The idea is that, if someone screws up and sticks a number like 0xbaadf00d00045678 into their rseq abort_ip in a 32-bit x86 program (when they actually mean 0x00045678), we want to something consistent. On a 32-bit kernel, presumably it gets cast to u32 somewhere and it works. On a 64-bit kernel, we end up shoving 0xbaadf00d00045678 into regs->ip, and then the entry code will do, um, something. If I had to guess, I would guess that at least IRET is likely to truncate if we're returning to a 32-bit CS. But I really don't want to start promising that we won't segfault if a different path gets invoked on some future kernel on some future CPU of if we're on an AMD CPU using their utterly braindead SYSRETL microcode, etc. So I think we're much better off if we either promise that rseq truncates the address for 32-bit users or that it segfaults if high bits are set for 32-bit users. TASK_SIZE is a super shitty way to do this. The correct thing is to either add some check to the exit-to-usermode slowpath that rseq can trigger or if we add some reasonable way for rseq to say "is this address a legitimate addressable virtual address for the current task's user space operating mode." We don't have such a thing right now.