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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F8C0C7115A for ; Sun, 22 Jun 2025 19:51:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA7758D0002; Sun, 22 Jun 2025 15:51:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5BFA8D0001; Sun, 22 Jun 2025 15:51:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6D988D0002; Sun, 22 Jun 2025 15:51:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 93FF98D0001 for ; Sun, 22 Jun 2025 15:51:16 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EAE3180DB9 for ; Sun, 22 Jun 2025 19:51:15 +0000 (UTC) X-FDA: 83584080510.06.F729C44 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf09.hostedemail.com (Postfix) with ESMTP id F2E69140004 for ; Sun, 22 Jun 2025 19:51:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=da7uhwEI; spf=pass (imf09.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750621874; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BUcrx2SGK4k7VspPrA1kZfeY9CvCdk1bQCrmf4AIFEs=; b=Rke607hrEp1QvjL+QY0lZzDqgRlTtP4fIMH1qHLJy6NOMSCykghMm3qGuc//X40pHQg11h tZP46WYySLAjDJqqdgovl53OjJQf03iltkPv9OfRnehelrwZMUot3nDNcERdscsg1AuP5F F1WlUlhXOad7Toanwt5LaBocUpDeQxA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=da7uhwEI; spf=pass (imf09.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750621874; a=rsa-sha256; cv=none; b=Kkhjzlg/Xe/89u2+0xOXH1fhRzSf0iox/ZnThymQRzfYeLrgcKEuQU7mxBQVZCQoz5KKNg efVU40tcVPID9dLaAbgJcF7uVWZ6/atYyvpPCBc9m8W9jO92C27P3Loa+8TZ2sb1FwL5f7 REcuonExoFXIJQimHiNRyweMXftqBqE= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-442fda876a6so31211615e9.0 for ; Sun, 22 Jun 2025 12:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750621872; x=1751226672; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=BUcrx2SGK4k7VspPrA1kZfeY9CvCdk1bQCrmf4AIFEs=; b=da7uhwEIGaPLcMxaVmYCJ/hwY3w+YPRB54MK+14eCju12CPfxNd/gE0GVEuQSexJhM ERCPy3LWkzTwcYjvjo/3NtebbDLr5ZTOaj+8wL0WEK7h8hv1Kbqc/9P6ADe5uQGEJw6i OpBi+D1+O83M3qqe5hVgY51AyX4ClfVnELZ/6McGekRNBeths91GsaEDywQDf1Y134zJ qa0+jypk4lWVS+Asbx7QVkkSUVXoi6eeqok0Gipfn5cyBjmzXb0wSWl8rOyKKzcNDQzH +FqpuTzSqKjxn0e9xPSjQPCpugQl7Mg5LCXGBQ8EwgZNI/ZYcqq85xLpTOKH3Kph2ney rWCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750621872; x=1751226672; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BUcrx2SGK4k7VspPrA1kZfeY9CvCdk1bQCrmf4AIFEs=; b=xMURs8CkkMY9ncxKUeTBGRHyrIbDjlDPrKX4N2EIpNLJcYdqWhuNmrRjy/q8YNk+68 kZ5zW2NIZL+ecd1qOS+wYSj7bOispTVPZcgcKJGpwkkIBV3tiOlvZC0Lgqzeu7Oy57Uw +xsp8QQNiTdpjEAzuhYzPso0hKWG57YG3W1jX4ZwMtVCL4k4K2UMeO3W39vwwE0zDkwe aNrLVshugLPKw+5iWP0VCzkuaW8LHtujQTh7ecihwXVX4EKD3d7ryMcaF2Hutqn+glzX TnrEfdLJ8FqESFulIgLuMCqhoGIje2gmznQqr5bybgznW8o/Rlk6f4fYVof0s0m1bq58 yUWA== X-Forwarded-Encrypted: i=1; AJvYcCVhkvwWv13e6HaS0itvVyKGTg/+CMHJmv4PYhCZ62iHQTTlvY+nJP4azuMQDBR658PXIPcI7SJbvw==@kvack.org X-Gm-Message-State: AOJu0YyuJ83LlLeJXN0q5UJkO3otDFCswTriAPwoneAxy3Awp4Bvgmpj LeBiVH1H8e12P2MnIQotayBaRRr4wxMa16l/Dm6+Q3wf/tp6edNwUkoa X-Gm-Gg: ASbGnctkpyF3MY0ue3Q/C8l+AJJxOxoqjZEzZrIWrB7uBQDo63ZnQrDnkGfm7CKyL0B 2VpIigU9J77cfz+VLJkMQ2EtdSPpytkvGzmmOw/qO20ZVDe1DVTjA206SmpU3vdLrKGeZGhoa4q eKYOKvqoDyK6HrOEG/+eWxjnPjCUc9DgXSeTjeArIQU5YuZytVBe6++YZFbcb+/dCzTNmB0qRXy M76HjDA0oRa3XSsIFhtYSrzBohLjR8TF+bw4rNZBUUZNIBFxX9o/S+SRRs9nkQbiUbzk+uYcWFg J9/Xqe2SWusJ+uk87Xhu9XYIJfk1M408EuGWimf2KKrUevx4ErXzakJ7twEusxQMTRVNRsDk1pd NlCNahGJxLGcO/jYVPn2P8bzr X-Google-Smtp-Source: AGHT+IGpGhtjsFvWIO86ULzWqyw8BmK+94ZW8xAj21rG1ZHpB7Q2zU99nx35rnDAsbLQBVkLd2sxxQ== X-Received: by 2002:a05:6000:4906:b0:3a4:f661:c3e0 with SMTP id ffacd0b85a97d-3a6d12e6a3emr7498266f8f.45.1750621872023; Sun, 22 Jun 2025 12:51:12 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a6d117c5f2sm7839533f8f.55.2025.06.22.12.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 12:51:11 -0700 (PDT) Date: Sun, 22 Jun 2025 20:51:09 +0100 From: David Laight To: Linus Torvalds Cc: Christophe Leroy , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan , Alexander Viro , Christian Brauner , Jan Kara , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Andre Almeida , Andrew Morton , Dave Hansen , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 5/5] powerpc: Implement masked user access Message-ID: <20250622205109.02fd2ecb@pumpkin> In-Reply-To: References: <9dfb66c94941e8f778c4cabbf046af2a301dd963.1750585239.git.christophe.leroy@csgroup.eu> <20250622181351.08141b50@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: F2E69140004 X-Stat-Signature: bt8zs59mure18jxhwfkijrypmwakte55 X-HE-Tag: 1750621873-183542 X-HE-Meta: U2FsdGVkX1/ob0zOedza9wuj4kOgl7CL7HYzRLXTTerSfTe2Sej+Yku4rRiCqef/CdsqQ8gvaDuqeVQC6HC9KGlD0wmyDAymgph0FsKPJEW3Vz2y3rlgK5PLIgqWH4I79FE2S8xOUU1PGcsLgFu/RL5pQW7vh2jZj7TPn28oFv1vysCpu4CwDbEoJi20UZs/1XL1BKSnhiIuVK26tBUBQGWEeKr4A7iILC1SPFoki9kySzhi0ZK0CvgAFh8IpZL3Q/8RBvW8YvTEJi1iBzIqXHYdt7Dm5ooqkjb4hf4SzKLqWHHaWZYXWRvLJA5roXoDoO4AvGhGKudbSxIxICvALooUn0TNEPxKYKleN9CI6avZWHn5Az1nU1D797/weCtSsf8suUIWAyKLC1RwjRtk/nbWRkQyphrH4ZIjIZZARPJZKpm4xD0W5DwHuh7TVpSpjWahTjnMdwgQoB9WiJ74YHtWh4YXV/KmAOmLJAPzTFFeZDmv8yOJ/pUzBu6xuzU1hNLzvWdPNqR0YHm/9a4ji5XvGNckMsPY53GgjbjLB3ePE5Axt4I5oT8S4mxuLrStaPp2WUZjw2xdcFKvaVfs0at+DkICrppwMgcPLdjmmguuuV473LcxWcjnjo35AlZ8nJqxDJkI0XVlLaWuUiS8y4wLZx26VuN2A3zQO3KdWwAbvMkHOFgBMBP/vFctPWB0oYZyN7oh42f5kSwoyZ4/n30G+ujjDf7J14xi965KTtfLVEgzxDWMKV3ICNz8Hp1QYh8OWf9bAli4egIq2//Z0Od3XBihJNEdhEpOxFCkC/q3OjnmskoLI8JbwaN8TPeFfWLrtsq+2AVu6GOG5U1z/5yFkXqaCHhiNUSRt26eme6pzBDGuTI3tBEWhmG9JMTyUytKJuP9V8HBLhekhbg63SO+D/l6QceFGsYLM2YImiG6V8MB8GrOaCmz8EbfsOpMhEWS6hToIDLub8jE7zA E+0NXMk0 g6R9Z6G+bGwLG7HpWdrePFGL1iGU466vvNDyrRsXyatTWXbCLWu3kzuVkxwmijNo958WOjwFRwjh2T365/R0Ch5m0tySGZI4wPar1X9Qur8foPySSYo9wBPFrv5nMPi6TNvOtewGtJGTAVc3qQruof5E27JC4J078q49w3tPzyRVIsMROOYsh5QL7vMq9izu/3JrrU3huv975nnLGso4zt56elfQKRLKhx0qtzgeqVSBTpeV4hq+JHwZlAUpvWmNnceOkIIjJ8YboIYmmPRiRgDXwJAw691t2fMqDIgodBgxZxTlq+9/ZuivF7xNPdlfLcCgLBImZzAgLaDSXiXs2inG6wvsTcITRjnHBUFwjwtv+SCC04iC/nZtl+df3/VVEzxxGqQ33ubJAyiOejcb2BeYF2No1yHiz6pTudcIqHfdG3T9sOmVOQP5dJsoUIOtjf85PnYH2vph8GE88jZUZsYFGFEEFpb1lW+oA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sun, 22 Jun 2025 10:40:00 -0700 Linus Torvalds wrote: > On Sun, 22 Jun 2025 at 10:13, David Laight wrote: > > > > Not checking the size is slightly orthogonal. > > It really just depends on the accesses being 'reasonably sequential'. > > That is probably always true since access_ok() covers a single copy. > > It is probably true in practice, but yeah, it's worth thinking about. > Particularly for various user level structure accesses, we do end up > often accessing the members individually and thus potentially out of > order, but as you say "reasonable sequential" is still true: the > accesses are within a reasonably small offset of each other. I found one that did ptr[4] followed by ptr[0]. Which was potentially problematic if changed to use 'masked' accesses before you changed the code to use cmov. > > And when we have potentially very big accesses with large offsets from > the beginning (ie things like read/write() calls), we do them > sequentially. > > There *might* be odd ioctls and such that get offsets from user space, > though. So any conversion to using 'masked_user_access_begin()' needs > to have at least *some* thought and not be just a mindless conversion > from access_ok(). True - but the ioctl (like) code is more likely to be using copy_to/from_user() on the offsetted address rather than trying to be too clever. > > We have this same issue in access_ok() itself, and on x86-64 that does > > static inline bool __access_ok(const void __user *ptr, unsigned long size) > { > if (__builtin_constant_p(size <= PAGE_SIZE) && size <= PAGE_SIZE) { > return valid_user_address(ptr); > .. do the more careful one that actually uses the 'size' ... > > so it turns access_ok() itself into just a simple single-ended > comparison with the starting address for small sizes, because we know > it's ok to overflow by a bit (because of how valid_user_address() > works on x86). IIRC there is a comment just below that the says the size could (probably) just be ignored. Given how few access_ok() there ought to be, checking them shouldn't be a problem. But I get either io_uring or bpf does something strange and unexpected that is probably a bug waiting to be found. Remembers some very strange code that has two iovec[] for reading data from a second process. I think I failed to find all the access_ok() tests. IIRC it isn't used by anything 'important' and could be nuked on security grounds. David > > Linus