From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48862C433F5 for ; Mon, 14 Feb 2022 20:31:50 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4JyG903MqPz3cNB for ; Tue, 15 Feb 2022 07:31:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=google header.b=JVRzXzob; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linuxfoundation.org (client-ip=2a00:1450:4864:20::62f; helo=mail-ej1-x62f.google.com; envelope-from=torvalds@linuxfoundation.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=google header.b=JVRzXzob; dkim-atps=neutral Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4JyG8C0ry2z3bTn for ; Tue, 15 Feb 2022 07:31:05 +1100 (AEDT) Received: by mail-ej1-x62f.google.com with SMTP id qk11so19479372ejb.2 for ; Mon, 14 Feb 2022 12:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uV1vHLzIr83T8MOCn12tMQAgRRvl8B7jglczOSl4CII=; b=JVRzXzobglXSiT0bLuA7vSr1HiJLXJeQF0BO276l66RCTCZjx8953KmFOVPMErrs0l on/NKX4mjsS9TS9bqhorHzBzM+OjtKgBLqdNoyLvrA639t1A433SV7/dJ5dxrhaCdPXH bTp5UzrLKiAt8Y3WQUfvdICLgLXk8cVAfLq1E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uV1vHLzIr83T8MOCn12tMQAgRRvl8B7jglczOSl4CII=; b=wwD3cEsSLmP+hcplRpGFMcPPncxhp26JjBIDqKOtBktFKRsDYcd7Mfu59sYPzJbMuK NtZGayWewNWJJj8isXHCBNenUToo/5qYxSv7CiucDtvy+stXp2WP4WlUp5UcgdjFs0f+ VSAXSpyM0k0KQEMXOEDigCDn+HEI6A+j+nYf9Tc74Vfs72jbXnGIeMpFH9z69Y1Czwom S3ehqUJ71I9WvxYmM68omFJvJ7CpALQQchPkc6zw1CwnjIqOZ5Rqdj3KSNJs9Y4W6TeZ LAmTs1qMO1pSFkgkxrXS+DygiZdP8hueP56kMm3FRtLSOv9yOlNJaRAz8+c9ITTimWdJ BDOQ== X-Gm-Message-State: AOAM5325N3P+6YiZiVZqpCo/Nzh57J/UztiqvxBMZUTzdvo9qCSeB9L9 eA9172/auT9Yi1nCxRQFi+PphAx8JfiIFT5Fx20= X-Google-Smtp-Source: ABdhPJy/vethY0V0en4+Yu4d07IXD3TpK5mbBd6zmCD0fq+DXYO8hG23G1s6Qk83zDGV7I4DfT7jBg== X-Received: by 2002:a17:906:51d6:: with SMTP id v22mr436064ejk.446.1644870662185; Mon, 14 Feb 2022 12:31:02 -0800 (PST) Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com. [209.85.208.48]) by smtp.gmail.com with ESMTPSA id t5sm5424312edd.7.2022.02.14.12.31.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Feb 2022 12:31:01 -0800 (PST) Received: by mail-ed1-f48.google.com with SMTP id b13so28978270edn.0 for ; Mon, 14 Feb 2022 12:31:01 -0800 (PST) X-Received: by 2002:a05:651c:1543:: with SMTP id y3mr306548ljp.152.1644870269711; Mon, 14 Feb 2022 12:24:29 -0800 (PST) MIME-Version: 1.0 References: <20220214163452.1568807-1-arnd@kernel.org> <20220214163452.1568807-5-arnd@kernel.org> In-Reply-To: From: Linus Torvalds Date: Mon, 14 Feb 2022 12:24:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 04/14] x86: use more conventional access_ok() definition To: Arnd Bergmann Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Rich Felker , linux-ia64@vger.kernel.org, Linux-sh list , Peter Zijlstra , "open list:BROADCOM NVRAM DRIVER" , Max Filippov , Guo Ren , sparclinux , linux-riscv , Will Deacon , Ard Biesheuvel , linux-arch , linux-s390 , Brian Cain , "open list:QUALCOMM HEXAGON..." , Helge Deller , the arch/x86 maintainers , Russell King - ARM Linux , linux-csky@vger.kernel.org, Christoph Hellwig , Christoph Hellwig , Ingo Molnar , Geert Uytterhoeven , "open list:SYNOPSYS ARC ARCHITECTURE" , "open list:TENSILICA XTENSA PORT \(xtensa\)" , Arnd Bergmann , Heiko Carstens , linux-um , Richard Weinberger , linux-m68k , Openrisc , Greentime Hu , Stafford Horne , Linux ARM , Michal Simek , Thomas Bogendoerfer , Nick Hu , Parisc List , Linux-MM , Linux API , Linux Kernel Mailing List , Dinh Nguyen , "Eric W . Biederman" , alpha , Andrew Morton , linuxppc-dev , David Miller , Al Viro Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Feb 14, 2022 at 12:01 PM Linus Torvalds wrote: > > x86-64 has always(*) used TASK_SIZE_MAX for access_ok(), and the > get_user() assembler implementation does the same. Side note: we could just check the sign bit instead, and avoid big constants that way. Right now we actually have this complexity in the x86-64 user access code: #ifdef CONFIG_X86_5LEVEL #define LOAD_TASK_SIZE_MINUS_N(n) \ ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rdx), \ __stringify(mov $((1 << 56) - 4096 - (n)),%rdx), X86_FEATURE_LA57 #else #define LOAD_TASK_SIZE_MINUS_N(n) \ mov $(TASK_SIZE_MAX - (n)),%_ASM_DX #endif just because the code tries to get that TASK_SIZE_MAX boundary just right. And getting that boundary just right is important on 32-bit x86, but it's *much* less important on x86-64. There's still a (weak) reason to do it even for 64-bit code: page faults outside the valid user space range don't actually cause a #PF fault - they cause #GP - and then we have the #GP handler warn about "this address hasn't been checked". Which is nice and useful for doing syzbot kind of randomization loads (ie user accesses that didn't go through access_ok() will stand out nicely), but maybe it's not worth this. syzbot would be fine with only the "sign bit set" case warning for the same thing. So on x86-64, we could just check the sign of the address instead, and simplify and shrink those get/put_user() code sequences (but array_index_mask_nospec() currently uses the carry flag computation too, so we'd have to change that part as well, maybe not worth it). Linus