From patchwork Thu Mar 23 10:15:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13185409 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 3FE59C76195 for ; Thu, 23 Mar 2023 10:15:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2EA56B0074; Thu, 23 Mar 2023 06:15:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B90ED6B0075; Thu, 23 Mar 2023 06:15:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A33616B0078; Thu, 23 Mar 2023 06:15:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 972BA6B0074 for ; Thu, 23 Mar 2023 06:15:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6E74C1C4F92 for ; Thu, 23 Mar 2023 10:15:27 +0000 (UTC) X-FDA: 80599755894.29.15EBD46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf15.hostedemail.com (Postfix) with ESMTP id 8D23BA0015 for ; Thu, 23 Mar 2023 10:15:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=qX0NvMt0; spf=pass (imf15.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 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=1679566525; 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=cY5q38znnygXEk7MQGfhMNT6fWhXSJdRMwyHM9vnLSQ=; b=wcy7d3EbgYxIOpqHZVzC78L7PmbhgtmmbY556xqHFiCzjLKIEHHumyI67GMmItFgyjS/Jv 7ZCRON03f7Jru5RUa2sT0ZTW4/iiUH2bwTH4H2+2HSKUBwWFt1aAdYbSX4XP6flA8/aYb1 gdr2NSH3nieRHIsscgnhlDuWrpmAsvg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=qX0NvMt0; spf=pass (imf15.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 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=1679566525; a=rsa-sha256; cv=none; b=NV2L8ppL9lkm2woOKHX6lDDbxMZGQTtFW02NMGv9fsykApLm+dD+B6WomKAVkuDUUkzXij bqe/Q+hoUhEZpyVvT68R9OwHkfsGQRM9oQbr5fHYP2iZr0fCeA4OcZ5FqnfTblsUVVnkDI VeBjk/v/z0A0q24rszX1VsuVGcFBXl0= Received: by mail-wm1-f46.google.com with SMTP id o32so6725173wms.1 for ; Thu, 23 Mar 2023 03:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679566524; 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=cY5q38znnygXEk7MQGfhMNT6fWhXSJdRMwyHM9vnLSQ=; b=qX0NvMt0CqzoY0Lr7UQkxPq2uVe4Zy3EMu6s5/qeG3l29H6nnTeBqXkDfUGl+sMJDi To1Uc1nPNJQYHElIFq5iO8fS+lk/SakYHnFC0dSfIt0VpQY8sLqg09eimJ/7YEqbP1XR VT8JBPbHX06JTtbWOk93ztG/5KD1q6ob99V4FihMHwv2MByqX1Ai3Z6znLATtnv+ksm2 c5FSk9J5/L8z0Co66rkYe1lq/fW2DO7o+YDkp/zAgdPysPTuJd1SALva7Z+nuzGuib3o K2iz/+LuOqaihmm/nmaxKKkG3rhp33yiI0LpXtvNIi6guzXD+7ckLO8ucQMHb28Rp07t X6fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679566524; 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=cY5q38znnygXEk7MQGfhMNT6fWhXSJdRMwyHM9vnLSQ=; b=0np/hvfD+eWCU5HiXZCbNX7Vw1TLmPQhG2DQGRAWmMHz2fN/YwmvlmSTjCiGzQJEN/ SL6ZZRuSrDSXHy4OaiLaBvYH67uJP/8IDbTzA+b0FCPKh3oWUPXY5XKX4ZjMg0iHuEv6 c4chnosSVZoF2aHRH3q9LXgTBmgfvOgNEPcgy+R2wF2T/kFwTz9jkNySDtmfi8Jb6Wke k6v42Ujoc9JgZ6RqBITDbBl0sSI8ClyBhIItMU8LNnZWPtb1CJ/NhHmI83073b/modoj hOhljzOvFCEHvA+9EinvzgNvLhtPHe4fq/jEBxKpzdPMtZfKmWq7HOdLpX1BgHpCruMd g1PQ== X-Gm-Message-State: AO0yUKXxd/nL3TIAczofb+JHuW95F5tqedT7rV8xu1QZkySIIBDQXBTB 5Wf2V6ebrGZMBiy2Cqw9ll9islli7go= X-Google-Smtp-Source: AK7set8l2mw02Hi+yEM7NEqPCCxbfo5h/cpPyKk3/TXqnMetKEQVjkCEfcASensglEf7x+j3LK9Iiw== X-Received: by 2002:a05:600c:b43:b0:3ed:2eb5:c2e8 with SMTP id k3-20020a05600c0b4300b003ed2eb5c2e8mr1890205wmr.10.1679566523681; Thu, 23 Mar 2023 03:15:23 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id f18-20020a05600c155200b003ede2c59a54sm1416952wmg.37.2023.03.23.03.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 03:15:22 -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 , Jens Axboe , Alexander Viro , Lorenzo Stoakes Subject: [PATCH v8 1/4] fs/proc/kcore: avoid bounce buffer for ktext data Date: Thu, 23 Mar 2023 10:15:16 +0000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: jw3meghe8jz6azdosko5ytuccoxujj3b X-Rspamd-Queue-Id: 8D23BA0015 X-HE-Tag: 1679566525-473851 X-HE-Meta: U2FsdGVkX196WUU95keuphxkRSHlNW8sz+J3obxZ+t3UxaGiYvqSdJgr/X4rcKDM5wk20qRTqpzRt46ajQCAHFAuZXbZYH8POwExMhwcfA2vEk8KfwAfO7Sf37tWZCLO3I6fRO85/5gnIqXfi9nZJkKhMD985U/ZvqZzInddPIeM9dLSwSCX7MVYsGWs7VC2a9UHhp40dc0zNPUUpLqUNWzD7jjmnpgQPKaetErx/P/QBRbP+xQi4VuB5nHRaM5zeVTMfVZMYH+hvcU6ab0dNzPb6AlC4RsUI7D8uxRFYC8Z4e8k8PDQboPvAZssviKMak2pPLqS4BU6VtjLzMtsGNfi9GNEG6aAVcQ5ydF0jxIHfPr3dF7RAf6fXi4JCFZb0dw2s8QLVDincnEEdIQam6KaodBDcZM6vvysZNpkZOuIm7HiHZRA0UZPec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K6KXiDr6kxspicv9sSjsk8oHI9WhfUR6CDyWolMNIZ06b06NjOnXuFAXy5G1Dy7ZOCEpibAk= 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 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: