Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp131445pxy; Tue, 4 May 2021 20:55:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyl3izRBj0WNMjLJhBuIByESM1I+cHigJbh/4sCnS/l8HI5jCQzFqJIsW/y3Y0oVoeWUShp X-Received: by 2002:a17:90a:e005:: with SMTP id u5mr32766716pjy.127.1620186936734; Tue, 04 May 2021 20:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620186936; cv=none; d=google.com; s=arc-20160816; b=0mdlXaMNJCR32j9KzEJmbv4bSUmfXw3OAEqIvjCpvY0lFGl9RLPsFi72t6bwh2jOLH devajq2UyAprJ2HVclrMdXXLJAI7nYRckqp/SxFDpSFL0SrEk9aVjm0Kke0Eby1paI52 yKxaoxlDUfYwJl2Bxe9KfxnZsHDV3XjhrafLKCuiPG1/cObRyAnNwWxxjJ2gJIjQdAID EP/JZxr7vzKQhL94IpFrvF5o+u6ky5N+SP6Y8l62ucUt1+b6ktW29pNDXqTY64SLua71 9fHeKNJeejDthMIkS/DtmLtPAHO1UY2nikvUSshpCtf6ekut1s4LK6lDY6ZRU0mWQiGt gKHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=N1QqSR2kJ89HqBrkHvTqK0OHz8+QW97ovsc8b69ofO4=; b=ZQjnUrViA2wB25TU9qRJMtrJQJVVNxlvYHO3IJYG4wyR/WHcj/7PBhQ8iM9vyaTRRp 6BleTpqqjJLMdBawx/xpg+ZA1atfHZvrKjARtrZPkAxSBT7R5d2GS/6RYw5X+Fl1wV4B ZdUZ1QZoPUSmxJLFsUE5sbB1wak34F6+yxKX+DWZSD6pUJU4m+q8uZT5OVFvm/4lyeE6 gYrGtyl1gBapI53AenlheA7YypGKzeCTAifUOgpwWXZTeL9xQ+zoTw9dkXfrLKJyBIAL 0z1HPb7oDwOG5XdzCyfB+fFnuB1wfCaM+eWDYMKWHfrizp03GKtjOICuCmawar7ZRoKB ublA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z09kAp6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id c16si6035373pls.4.2021.05.04.20.55.23; Tue, 04 May 2021 20:55:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z09kAp6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231319AbhEEDzq (ORCPT + 99 others); Tue, 4 May 2021 23:55:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45167 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbhEEDzq (ORCPT ); Tue, 4 May 2021 23:55:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620186890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=N1QqSR2kJ89HqBrkHvTqK0OHz8+QW97ovsc8b69ofO4=; b=Z09kAp6K/Qxgk2npz4xFqMqLLkJxKaA6tU8Aqzr6Dr+Dl2cRcLYEGIi1gRmRUuZzDjyoSY tCnm84ERiy67Cz9eBHcPRkd9+h9VviDY1nhTCNKphyVMHAAvPhl65tEUJgwhjIU3aohmG8 5yVlQkKr80D8xaQ+oZp/WBwIkRQ9mfo= 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-296-fIHtToMSMB6UHtkzkjmpxA-1; Tue, 04 May 2021 23:54:46 -0400 X-MC-Unique: fIHtToMSMB6UHtkzkjmpxA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DCAA107ACCD; Wed, 5 May 2021 03:54:44 +0000 (UTC) Received: from treble.redhat.com (ovpn-115-93.rdu2.redhat.com [10.10.115.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B651002D71; Wed, 5 May 2021 03:54:38 +0000 (UTC) From: Josh Poimboeuf To: Al Viro Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Will Deacon , Dan Williams , Andrea Arcangeli , Waiman Long , Peter Zijlstra , Thomas Gleixner , Andrew Cooper , Andy Lutomirski , Christoph Hellwig , David Laight , Mark Rutland , Borislav Petkov Subject: [PATCH v4 0/4] x86/uaccess: Use pointer masking to limit uaccess speculation Date: Tue, 4 May 2021 22:54:28 -0500 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This one managed to fall through the cracks back in September. Here's a fresh new version. Ideally, we'd switch all access_ok() users to access_ok_mask() or something, but that's a much bigger change. I dropped all the ack/review tags because the rebase was significant. Please review carefully :-) v4 changes: - Rebased on the latest. - Split up into multiple logical patches. - Renamed "force_user_ptr()" -> "mask_user_ptr()" to prevent confusing it with '__force' casting. [based on Dan's comment] - Instead of reusing array_index_nospec(), made a new separate inline asm statement. Otherwise it fails the build on recent toolchains and/or kernels because the "g" constraint in array_index_mask_nospec() isn't big enough for TASK_SIZE_MAX. I could have changed "g" to "r", but that would negatively impact code generation for the other users. v3 was here: https://lore.kernel.org/lkml/1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com/ Josh Poimboeuf (4): uaccess: Always inline strn*_user() helper functions uaccess: Fix __user annotations for copy_mc_to_user() x86/uaccess: Use pointer masking to limit uaccess speculation x86/nospec: Remove barrier_nospec() Documentation/admin-guide/hw-vuln/spectre.rst | 6 +-- arch/x86/include/asm/barrier.h | 3 -- arch/x86/include/asm/futex.h | 5 ++ arch/x86/include/asm/uaccess.h | 48 +++++++++++++------ arch/x86/include/asm/uaccess_64.h | 12 ++--- arch/x86/kernel/cpu/sgx/virt.c | 6 ++- arch/x86/lib/copy_mc.c | 10 ++-- arch/x86/lib/csum-wrappers_64.c | 5 +- arch/x86/lib/getuser.S | 16 ++----- arch/x86/lib/putuser.S | 8 ++++ arch/x86/lib/usercopy_32.c | 6 +-- arch/x86/lib/usercopy_64.c | 7 +-- lib/iov_iter.c | 2 +- lib/strncpy_from_user.c | 6 ++- lib/strnlen_user.c | 4 +- 15 files changed, 89 insertions(+), 55 deletions(-) -- 2.31.1