Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp108565ybf; Thu, 27 Feb 2020 17:05:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzWDJALT063OqAcXxivUsNFgJ/sBPr6xhhCRdR1dwLdqPDzxdAX/LDGYmRHRJsXhMJrLHCk X-Received: by 2002:aca:5150:: with SMTP id f77mr1383043oib.52.1582851920902; Thu, 27 Feb 2020 17:05:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582851920; cv=none; d=google.com; s=arc-20160816; b=X9/IGk7NbtYR2P0ASq4MgfwWVItt3QL2v24agXb4cxKJFGZUZ8PtxP32S4EYHygLqE FiXy1K32cOwRgTBz5tHf3XdESTyePUg0pTX58ajDdHlMczJXr8g/KJQUV2c9/dqZATMJ fvwGTxSFWwYh+P/ombfw382Re5BxfQfs2xbH0EjEZCqvzeXZ9yG47HBv07OEfFhAf6B5 XWPRBe2qjanD1hYHMXXALoYVVLbpGgPAcEKSaydS0qolximMx09+/Zm3pbz12DjNU1zb wfX3wtxI+sFlR9kzZ47EXE26R6xwN6SytW2uuDX0q84uA8g0vfKQN20JcA5NGRBG3ThU /qfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=hRN8eHua6qZxJSEBJTd7eqSNMS3wRQFEAkDzQ0pIXII=; b=otqKPd+aMMxBLCRxk3YIp9nQWAiuA9SeNDyEsXCRztLH7jo0m+57DveRzCf2xyAfcH jG1dwVpnZI0mLVVtzPOPRMG5Gn3YxYp0NEHA9Bau9+3E6s9AyDnQwYRP7SED0rT5tKPp mNRD9VAYFrQ8io14v1j71JO1z6HshX9Z1YcRlS770UrJmJDGbOuc+YuAFu6Kf+cq/rQW Sg8tcv1PcyA/TYQqSMkYulsnvszfI2RuWrZCA2LBOqztiWqVhVPD+2q7QmBigotM1TBm wZQd0N3SOX3Eqsufe2ibB0mULz+f4ap8h1nUy4HWbpgd/byDcH6EVSfkLir0IqiQvPa9 EKCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CgQFtkvj; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o206si930831oih.143.2020.02.27.17.05.08; Thu, 27 Feb 2020 17:05:20 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=CgQFtkvj; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730363AbgB1BDy (ORCPT + 99 others); Thu, 27 Feb 2020 20:03:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34142 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729984AbgB1BDy (ORCPT ); Thu, 27 Feb 2020 20:03:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582851831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hRN8eHua6qZxJSEBJTd7eqSNMS3wRQFEAkDzQ0pIXII=; b=CgQFtkvjAN7yJSlF6N6YGFFYto3ErZgp6bU8v/tKbSGRLcrmdIUIXdM5NAY/jkZqF89FAy da6uFRlTrZIGfnlW2+14egQH34K6BLaWU5k+HWiWG8mgy8G3Qcl6J7E+Xq/CZGjcavlswE DqQTdQtydexWw7+9mhDZHxH6ZT6Lbl8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-CaWvg9btMe-Ck7SyAYdSsw-1; Thu, 27 Feb 2020 20:03:47 -0500 X-MC-Unique: CaWvg9btMe-Ck7SyAYdSsw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECF09107ACC7; Fri, 28 Feb 2020 01:03:45 +0000 (UTC) Received: from treble (ovpn-121-128.rdu2.redhat.com [10.10.121.128]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCABD60C18; Fri, 28 Feb 2020 01:03:44 +0000 (UTC) Date: Thu, 27 Feb 2020 19:03:42 -0600 From: Josh Poimboeuf To: Al Viro Cc: Chris Wilson , linux-kernel@vger.kernel.org, Randy Dunlap , Peter Zijlstra , intel-gfx@lists.freedesktop.org Subject: Re: [PATCH] drm/i915: Minimize uaccess exposure in i915_gem_execbuffer2_ioctl() Message-ID: <20200228010342.3j3awgvvgvitif7z@treble> References: <20200227223542.GE23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200227223542.GE23230@ZenIV.linux.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 10:35:42PM +0000, Al Viro wrote: > On Thu, Feb 27, 2020 at 04:08:26PM -0600, Josh Poimboeuf wrote: > > With CONFIG_CC_OPTIMIZE_FOR_SIZE, objtool reports: > > > > drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: i915_gem_execbuffer2_ioctl()+0x5b7: call to gen8_canonical_addr() with UACCESS enabled > > > > This means i915_gem_execbuffer2_ioctl() is calling gen8_canonical_addr() > > -- and indirectly, sign_extend64() -- from the user_access_begin/end > > critical region (i.e, with SMAP disabled). > > > > While it's probably harmless in this case, in general we like to avoid > > extra function calls in SMAP-disabled regions because it can open up > > inadvertent security holes. > > > > Fix it by moving the gen8_canonical_addr() conversion to a separate loop > > before user_access_begin() is called. > > > > Note that gen8_canonical_addr() is now called *before* masking off the > > PIN_OFFSET_MASK bits. That should be ok because it just does a sign > > extension and ignores the masked lower bits anyway. > > How painful would it be to inline the damn thing? > > static inline u64 gen8_canonical_addr(u64 address) > { > return sign_extend64(address, GEN8_HIGH_ADDRESS_BIT); > } > static inline __s64 sign_extend64(__u64 value, int index) > { > __u8 shift = 63 - index; > return (__s64)(value << shift) >> shift; > } > > What the hell? Josh, what kind of .config do you have that these are > _not_ inlined? I think this was seen with CONFIG_CC_OPTIMIZE_FOR_SIZE, which tends to ignore inline. > And why not mark gen8_canonical_addr() __always_inline? Right, marking those two functions as __always_inline is the other option. The problem is, if you keep doing it, eventually you end up with __always_inline-itis spreading all over the place. And it affects all the other callers, at least in the CONFIG_CC_OPTIMIZE_FOR_SIZE case. At least this fix is localized. But I agree my patch isn't ideal either. -- Josh