From patchwork Sun Mar 19 07:09:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13180240 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 15BEAC7619A for ; Sun, 19 Mar 2023 07:09:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5A38900004; Sun, 19 Mar 2023 03:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BB4A900002; Sun, 19 Mar 2023 03:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85BA9900004; Sun, 19 Mar 2023 03:09:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 758E3900002 for ; Sun, 19 Mar 2023 03:09:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4424EC0263 for ; Sun, 19 Mar 2023 07:09:43 +0000 (UTC) X-FDA: 80584772646.29.EF2D82C Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf08.hostedemail.com (Postfix) with ESMTP id 68E70160018 for ; Sun, 19 Mar 2023 07:09:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=E7BbUYx2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679209781; 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=WomgqGsgyODJyBug702f3XGPw9PAb3aLGGN6xZJlri6g/z1j/XAMnJcZqXvU8V0goPba9u PRcjVrzVnlibBNNELxWRAHtOv0wn6DEo7TqyRQY8yZajJAzHs6cVDDiUgouTnungmkXSNe rNxL6lCaAwrjEZqlM53ruDdbrVuGA6w= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=E7BbUYx2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679209781; a=rsa-sha256; cv=none; b=Qn77JZkldededNhEZAHRo1XL0IjR+t5YSWTx9tQt0fDXPbqT/j2Tr2UDxlzEUpORrI/k0L /L6nq+XfwfbwOk3DZIMzVGU1HpaOrqqXZV70avU8KL4wLNEUaFBLjbeCGEF22fvvZzACPO eQkk36kPD7/jXR6iVw4Ucjj3TJKfGE4= Received: by mail-ed1-f51.google.com with SMTP id ek18so35442045edb.6 for ; Sun, 19 Mar 2023 00:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679209779; 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=E7BbUYx2VyQn5O1pHGy3AFX0ymfBCLHPKP5Y3xZwRpm/H/ORpIqsSyumlzF6fxFTMN SY1a+7FlryqU0IeYC7yS4qjOhenHYnANyIqz2mKvafPCfKBU2PnV33pqBXOs2JOCZIIL +KD1JgRFeZhX8S0bSCi1NovBHbT/CTaf2CcMG2IL1dgmBzSHi8Oe8r29QIyjxDH4DEip rbMrF2R8NWa5WZHFzuhkQhRmOu8CnVhC9Gs61cOqvXaFBehc1LqJzAofSWFI+eSCjmF0 xIHOYl+VudPK5mSG4x7D1PTE/K931ydfuzIGMidUKyKYP9nmi0qrAlxd0Mlo3UBh7+95 CcfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679209779; 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=T79A6y7ehNmg0u7G0kVQhzbR++3KZzDvBt5gk6T+yer3S4+z4zBLi+QGRIbvMuO2s5 eHv+TXV45nfZdjLr/yrbL8qEGwko/yiGiHODxa/GywTkUB4j5YVBLMXjrQQoNfHYpUlC yOMGn4Z9BJ9If61mGge8RLgCGm/Rkn42QhW763yo0BSLY7rQMNLEnzW6PW850uGUPOTJ c+gqWbC53mTejaYEZmveogv8Ht4T34BY67+3FK+FDI0+KiicJwiL571pAyWIy92CpxOT fxshUnqkYbbY3wCVyykkoVa/HkSNdp3VHcFNyXFVvcRZRskLkuB+0ZO416ZsLgfZvQ4D Vqrw== X-Gm-Message-State: AO0yUKU+jtoXIP4APiq2MIMGURR3HtF0z+VPDSRD8z8uNwQr5rKpqORA knd8zz0Q0ewoh9UDRrunRgKNfXClFao= X-Google-Smtp-Source: AK7set+W4lasYomB07kPXcM5wE+qUni1s4ui3d4L4qeGtG0Gv+O2Px0+D0Q0CSaktIqhgOZmF0Xktw== X-Received: by 2002:aa7:d744:0:b0:4fd:2b05:aa2 with SMTP id a4-20020aa7d744000000b004fd2b050aa2mr9076089eds.42.1679209779674; Sun, 19 Mar 2023 00:09:39 -0700 (PDT) Received: from localhost.localdomain ([2a00:23ee:1938:1bcd:c6e1:42ba:ae87:772e]) by smtp.googlemail.com with ESMTPSA id u8-20020a170906b10800b008c9b44b7851sm2943920ejy.182.2023.03.19.00.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 00:09:38 -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 v2 1/4] fs/proc/kcore: Avoid bounce buffer for ktext data Date: Sun, 19 Mar 2023 07:09:30 +0000 Message-Id: <2ed992d6604965fd9eea05fed4473ddf54540989.1679209395.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-Server: rspam02 X-Rspamd-Queue-Id: 68E70160018 X-Stat-Signature: g8mmryymmp461erqeu1xa6j9aoiotzch X-HE-Tag: 1679209781-341454 X-HE-Meta: U2FsdGVkX186QhrDdGeTROP8B0sNE7sQaAb0f3bzb+ZLbbRYnjoOI9SCPOCYwaMsZb1qz3ICoBAW5hYlPuwj0x5iW7izn+Cs8yYqNe0DPIw+qd7CW1Z7mGtZ4lXXFKTqtA0NmI3W/Wz6qawGHTRwcHC5OPOyGZqAE/NAwqQAYXMveFz3dDyiWOS/X6vt24J7roNxkkiATWRuIETloE3F+v9AJvKDPMuBjbD7GNIt3zKrZbLlvy7C8L6/Vjsl9VGoaWBm8WaObsLCzDvCKXsif+FO1bA34NIC+z8kIn6Vg7TlMGr8fsZoG3zOcMx8UICcrixpTTIytlhDocd00cx1t02RR9N6w/Q1ydF1zcq8tOzqDLZd98HVifFMI00J/PvHy4XnrogYLK8MLLK9Ys4g+E+bHBhvoBn7dc+Enl09PL4hwJzm441vfB8AstIkJ4kZHnK4Ow861OOHgRFBEmi0Kp0z5z0x5+i7I86OAt09D7xakBhGKegb+8IpwBeqxdvYHOWnvbRkDzO+aKWM6We79Jc9P71iOuBI4JFL0AoYsADIgVeVTUf/Vnw6LjzoM4xyHbS3TfspRCUe+/+ehpfVWmyqFMu4dsy7Ts5PPI8w+995H6O9Lp21zHQwoVc+xp2fHoAD7n1xw7knpzw2rsACmBU7jFrxZ1ZxaF8l0fL1XotcX9mvWgUTIYUcy03gfanimZqskvD1m3TWlgEUpHfyMpgArWyfF3THsmEZGNRprrl85gCaPC+nCDsABbwxqNEVwoubMa6tbuNO9q1IiFzxWVifDhFB9ACKzAlSS7mM/+6lbJ6y6oVWuTjV1cyXf2RkOd8Tm6tnKfwqNkEfs+mbx+KwA39m/rjCQM3dIZ67u4dVwtOPXRcg3KGYHUFLl50jNqUaXL3ZDBCSFd+APOa17xq59dpgt4ZWMGkpY62BDeb0TVx5vFE15SZltWra3L/fHTCclsVtqLIzVZJ4nd6 +czxOAsn xD5M92JmdcQPdfjsEr53z5G4PbYf9AGzHdqKS9Tw7x/mDNXMkpuAJjD7443aMyqP7Jm6vieVmC3U8+KeojaaormT85PMgZKkrH+CaJfri92Hplmmge+eY+8f/9wlEpmlfA8fxC9NJmSudmHl6pTxnrirTq6Vi8/J0PEFYxqQ7iTa9+6a3KMblKmvix/bP3kJP9WwwRpSU7JhqVTiE2HZaMmnHsTzcMGLJBBQ5HD3/tt4RoygBqcsvcrzt1F1OSRUVtXIuLW+k8AJ3run4oWYxjrMU+W5x9ZmjCCVrmN1h0UMxr5SfAYNSPFzNEQ97Xq884cdySKuhWk6/lf/3ByQVFf3iNecSpUjRCGPEnbJsrc6lRlQFeoqwEnFFPTkhe3l450vjp76pVaQZlzYKcmqWUKYp4yYfwZ/BjCWXaTMQHMIHzaEGpd53p5pf+wnPUcmfmjWl X-Bogosity: Ham, tests=bogofilter, spamicity=0.000103, 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 Reviewed-by: David Hildenbrand --- 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: