From patchwork Sun Mar 19 00:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13180170 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 B00F9C74A5B for ; Sun, 19 Mar 2023 00:20:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37C97900006; Sat, 18 Mar 2023 20:20:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DCDB900004; Sat, 18 Mar 2023 20:20:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15741900006; Sat, 18 Mar 2023 20:20:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F3018900004 for ; Sat, 18 Mar 2023 20:20:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D22B9A0D3D for ; Sun, 19 Mar 2023 00:20:20 +0000 (UTC) X-FDA: 80583741000.04.C116927 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf25.hostedemail.com (Postfix) with ESMTP id EEF81A000E for ; Sun, 19 Mar 2023 00:20:18 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nC6RYf6j; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679185219; a=rsa-sha256; cv=none; b=3tQQEk+ear7evGUQNpJK3RXU+8OvgLKxKE+2n46xr+MMIgs3KmPGRgB66yp3JrJf9ZVaEe vl2zRxa9EekSttX3lbjlKNmdgSfUH+nX6eIib2PsmdJLXYTpf7rP6lpJH3Ne9/mrGZyp9Q g6Tt65Nbl0Kh4YRRaFKDQ+JGE7kz29E= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nC6RYf6j; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=lstoakes@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=1679185219; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=csP2U+h4A4N+JyUsV24C6SnnqlSeb33JonwK9o1duFk=; b=duFc4SguXDQfM/uoPw80+wj6tknTeUtEX9UI0UtJJYQ0lMxdD/5JfkiLRoxjhjdxTY0I8E uFNQoRFU9u5+BgTqgu0S5z+QWgr0k1cn+l9DUsG69DI09UaiP14T8PMfYJOwEQygF0DxyW XuZ6cC/wkYjZOJXWXuc9n8BSlDohgqE= Received: by mail-wr1-f53.google.com with SMTP id t15so7374171wrz.7 for ; Sat, 18 Mar 2023 17:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679185217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=csP2U+h4A4N+JyUsV24C6SnnqlSeb33JonwK9o1duFk=; b=nC6RYf6jBdzIKQ4o3vm7PvlkCYMlOb1FdP26eTaA7XVeOCh6KBdfA7t8A9kV0DJyUu Zla8U4rG4p3JsUlcTbj1hALd7X+zuQQyHPo31R1hXSlO6RI1L+zQQ6nLiJl+1/Xd7U7U apPCOgsxAoHSLFM0qPvVpo7u61XC0kmIRa5pxuaYfocJcUN0AOST09bBvQuEcJGH8esh Ib/zsOkFPFJkM6s012r+iEmCzFsVMHBLJiz8a/qppPITwzE0psbE/fxPchSR/bE9d1mw OfIHu0q2z+2gyGNfQdqreV8GYmkXjgOOuUaUsHA43nqXVPlwr56UszPzKQAefMoPfCHJ 5Cqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679185217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=csP2U+h4A4N+JyUsV24C6SnnqlSeb33JonwK9o1duFk=; b=e6bhgt8xPxFTl+7NYB11q0e4cYKRgCvLb2DIk0jyhqmdC9On2oHa/WeB4w9LgAABLC V3ZbLvQnInrDOXh8f64FWAsWhoPakMfzc6clhMVT54QzcuLdWUXN4abzjLev9z8FKIq2 ai8I/ItBnNt3pTTrdywWWJ+IiRi0W8WoQqhzZ+1v5i/7c/ObBn7uqOIGyIGXGm/2dSpp L70I6LmryGTNEV6QivXoBuVCSfmDBiRHN8KXCrSEBA4kFZe/2pbAHtgdCd5fa8BEuwVt Frw2tmqpGCvopQD+MGS6zrZn0Shunu4PzCCbPimegjcKra/ZaIhOfArS67zWU92L3xFM voEQ== X-Gm-Message-State: AO0yUKUagH58fpDw3U6BV/GFbYE/gIcGMuPsfZHpUkndXLh7io+wRRwd Tv5AOo85cybLZwMKXcwEahNSXYU1dxY= X-Google-Smtp-Source: AK7set+dDEGx+X3Pskgz3ooddARr7XyBMTyRwnPZALsSabKkf9CNmLvTCoIx1rhzU9tGuRxE4a3syA== X-Received: by 2002:a5d:54c1:0:b0:2d3:fba4:e61d with SMTP id x1-20020a5d54c1000000b002d3fba4e61dmr4877179wrv.12.1679185217216; Sat, 18 Mar 2023 17:20:17 -0700 (PDT) Received: from lucifer.home (host86-146-209-214.range86-146.btcentralplus.com. [86.146.209.214]) by smtp.googlemail.com with ESMTPSA id x14-20020adfdd8e000000b002cff0c57b98sm5399639wrl.18.2023.03.18.17.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 17:20:16 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Baoquan He , Uladzislau Rezki , Matthew Wilcox , David Hildenbrand , Liu Shixin , Jiri Olsa , Lorenzo Stoakes Subject: [PATCH 1/4] fs/proc/kcore: Avoid bounce buffer for ktext data Date: Sun, 19 Mar 2023 00:20:09 +0000 Message-Id: <2ed992d6604965fd9eea05fed4473ddf54540989.1679183626.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: EEF81A000E X-Rspamd-Server: rspam01 X-Stat-Signature: 7j3ymnddp1j9qfgm3ex6eaqwjw4w5nbx X-HE-Tag: 1679185218-635169 X-HE-Meta: U2FsdGVkX1+54vx7sJcaFMq4wWqvtkCxB26XPrNHAxtPlqB9zCrpiYmqVHgdRvBWUH0hz14OvgPj99brHUDJPhu8DXMNH8VbuNb3QdWA8R3/Shme5yGpTrJ8XbJSORgAF/j1SnUJlyycHlyyfhReK7+qfHEkqZgEMQDS6Br17YrxNf2n9wGNBZ73aDcLm3AA0tqtOzcFJbqREdX5DQINenhViUGrvnlGXy9RilXt3AGTuoB0TRVnGQZDAVl+f0iJE6KLyIDe81NbyzSOiBZSIj1xdCYJHwueWMLhjmqu5n/Yy0aJUFaccvelveT21Ea9f3GOOC49KQLQd9kfy1gKnRxERmSezgKmm2tcZUTM710FAmFvKxAWD5A6cysSTORNMZDhySkQCjqohbl6wSC/csp2q9Me4/GOug77zMmrsyeg6MHSLThJWO2xLtPTyjn0phzlXGgK57KZ75nV0xHb0+LjfD6+bgnSakeaGRL3KamFQ8W9SE2a/QjO+R4N5QRTSTP5BJqJ1g0k2zTw45gs38t5Err9i+e5/rzKdon/4suwzakfor6AUYh/WSvH+D+smaYiGFYuZZgzXhcffzb6tsetlzvLyePbwrqmygtAYbiO4ekPw0qKW1Zy1Ij9WljyanVtHUReDtyrqOTbL9ukxvVHYIuhYv8IgvrlxRUjng+PNzJpDzvvQfYpEJjxxMpAhUXfqxoxWztEpwEEhgBzV1BMs8ua9SxKhMyXr3wyloqSc4iXot+sevHPvbk9s94EJss6bFsFxfElue0cxIWznNtZlZNPjkWudSQ2mrXPId86ShQPXOdQ0yDp2g87+UpebOMwuKbEeEZ9fwhJg8C8Mcq7c7b4ph7jNo+VIdYyryPKuIwVYr+4OqtYT3SiWnClX+sBYEKN+iC6wbCeuznbRC1BXmt8vCXFj9Ka1sqIgr10hq7gEL16Fax1h5OPtx9ybrI2BqLQs1zeB5vhAJG 9v0qdtUd RcyCYv3Qs6SU7E84MeI+Qly2WrIXY2o6HKaUNbV4P7rVJ85UZ5W2c7IqSl/HBrENS9EsKnhASfPpWEq3AEIwwBuTQpFrvnJaP5TqCv6spNH8+NOrK+6jGmq4r6UafqcG2ZpOFkkftE5UdE37j8XnCI+iYrKxNYpdFVoPiSk8jS7y3PYGFlSFHc54QGGczhO16/RhiUwimc/86MLT6kKAFzkGO0JI1KQbFoT5TljYTfr9P/KyEssI6ArEp9izsgj9LPYpbFr68uWFb/tYo8AEFJm1r8AOhM16m2i7R4M9qrIUd1TraQnIMZW0RTUgESdnfuP8Sdyqeyg5Og+5PmyQWFJwsaU6nCd4HFZhwLwyRhf4xfRhhHAUEm4NXE+TiDUMXHjOVpUVsmD10UsCVtSb+4o7snHcRKbL4olLmclj9UkKmG9iw8C1eQu8KFWyaeuHNurDvVurlUKIKDdA= 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: Commit df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data") introduced the use of a bounce buffer to retrieve kernel text data for /proc/kcore in order to avoid failures arising from hardened user copies enabled by CONFIG_HARDENED_USERCOPY in check_kernel_text_object(). We can avoid doing this if instead of copy_to_user() we use _copy_to_user() which bypasses the hardening check. This is more efficient than using a bounce buffer and simplifies the code. We do so as part an overall effort to eliminate bounce buffer usage in the function with an eye to converting it an iterator read. Signed-off-by: Lorenzo Stoakes --- fs/proc/kcore.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 71157ee35c1a..556f310d6aa4 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -541,19 +541,12 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) case KCORE_VMEMMAP: case KCORE_TEXT: /* - * Using bounce buffer to bypass the - * hardened user copy kernel text checks. + * We use _copy_to_user() to bypass usermode hardening + * which would otherwise prevent this operation. */ - if (copy_from_kernel_nofault(buf, (void *)start, tsz)) { - if (clear_user(buffer, tsz)) { - ret = -EFAULT; - goto out; - } - } else { - if (copy_to_user(buffer, buf, tsz)) { - ret = -EFAULT; - goto out; - } + if (_copy_to_user(buffer, (char *)start, tsz)) { + ret = -EFAULT; + goto out; } break; default: