Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5990943rwb; Tue, 1 Aug 2023 10:36:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlG8yaL8jQyP09zqgiixeP8pcch5sA2VZBGfU5TIOFmoE4qE4s10Kuqx5AwiOmoABCBcfy+q X-Received: by 2002:a17:902:e745:b0:1b8:8682:62fb with SMTP id p5-20020a170902e74500b001b8868262fbmr16408290plf.4.1690911378738; Tue, 01 Aug 2023 10:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690911378; cv=none; d=google.com; s=arc-20160816; b=YAOIWYpmDueOx6l0c0qrILiW2wBGuXkxdQUREUoRxjaZGJM//6J6bbrZ2fVInT+lHr WlDHR0fB/h1VDADDv/V5niaCdBecvKFnEz6ciKp9g3fHIxclEkyAwHcmmUO/yIYYconM PsRPWVZjS5ijvmzPiqELChe20t6TjroZB335skCemXXhgTJCgLJ1ukIDjTJ5nUngcuPo 7iyLiyD1thc6yepv9gEcMx4/TDQl6djr5erFXATteUfeeHRZIxeKoSJcZyfylW1XuSWq BIS6Mg4yjaGTJxmgms67264tn8UBiuE2GvOfG2IjIYEf7w/ESFNGpnhO/Wxeqfphjxrn j3lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=kjefxxv3ZRGBWfEsXOGOuERDMNqo6jQLqyrxh73Gpjc=; fh=pJ1+BCBctV4yFfncc1KxcaAFPpLxhxUJnAlitxKpYlo=; b=qWxzSk8biw+dD9ygn7CayIl78WE9r1Ud6MZMvRIFLDN5qgWhcfd6xf/oCGP0rjEh39 32M8wjzEmBL1caiI6SKC478bjaiIyseYmtxG0Yaa6RtvROn9asGhB5h6f7JXUu9w+4Ad G76wrQGhmU/VhWp4OxMrBIvjq3QLqLINv84uKJyZS1oORIEfuhq6O5t0kavGOADfiSaU mMjUBHCFZif+tnIOPacSPsYKdEt8FeihqvmYIGKnI1a1n40+/Csq4Ytb/R+HoLL3dYCB mIqyEnfy/X7qq0eVNrNT4VL/7viNhuBSzRvQq/jKC0brRN3lja2PtmD8BAwvC/wU6PDv QjoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bqv+kHt+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a63d043000000b00563e1deea73si8991618pgi.39.2023.08.01.10.36.05; Tue, 01 Aug 2023 10:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bqv+kHt+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjHAQf0 (ORCPT + 99 others); Tue, 1 Aug 2023 12:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjHAQfX (ORCPT ); Tue, 1 Aug 2023 12:35:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE3E72115 for ; Tue, 1 Aug 2023 09:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690907671; h=from:from: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; bh=kjefxxv3ZRGBWfEsXOGOuERDMNqo6jQLqyrxh73Gpjc=; b=bqv+kHt+sGJ8+Pw7ZbpfZtC2SwnpE7y89vBUa1bjW+FBE05/S+QKui0xku/NjAf3w0sHUG rSG9RcMp0Fx/EPs7Y4CXIZKN5YG5Ve1G/1H8LuHOhf5ub2DAFn8iAEl88fepEGlUme8fY0 YTbNniiO/e51ZbVJUyekO5Ta4T7R+uU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-ze3k6AnfPEqFOAdmMi8tbw-1; Tue, 01 Aug 2023 12:34:29 -0400 X-MC-Unique: ze3k6AnfPEqFOAdmMi8tbw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3176fe7b67bso3153973f8f.2 for ; Tue, 01 Aug 2023 09:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690907668; x=1691512468; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kjefxxv3ZRGBWfEsXOGOuERDMNqo6jQLqyrxh73Gpjc=; b=ZZGeoe2Ycy6DklYQRLZjMrUqACmXaK7cndsp42ZYtizndX4z2zCev4FRDTEhKWfeSC le6JpwQ8M7FAr0u7YssQAISZwy7hSr5yQ8HJ9PzFW/VY/1MLoNQPEOb7z63toaJltAvW xywJeFHaBFaE/qdmrJ45+lbk8tJOk5Zhg7brmNbsdtKSZ1+oeS9q/4y5p8ytpWwooOHX y6n3eW9C3dBb3+5wcLzW892wIbXX5El25ZpuBGFZaqcQPkNHbgeaGbg+bzeCYUBEVOM0 fep9PS+2pymqV0UAOJnMK02shYVbqCeM82/uLYi65ZNSLNxhgTCBDw0IBgGbJoZ2mhfp 6XRw== X-Gm-Message-State: ABy/qLYvEBFqgi22WPqaJShPww2FOlVAJrV+jU0/mngFbNiFLU43LCX0 UJ97ZNn5kv65sZglb1E/8JiEi042eDrteVk962ZYAnpr0HqRY3T4RhxyG5kexrsIUDhxxIj7GBB /sMOBgg0TofNQrV18f304VmWF X-Received: by 2002:adf:fdd1:0:b0:317:5b76:826 with SMTP id i17-20020adffdd1000000b003175b760826mr2809304wrs.0.1690907668489; Tue, 01 Aug 2023 09:34:28 -0700 (PDT) X-Received: by 2002:adf:fdd1:0:b0:317:5b76:826 with SMTP id i17-20020adffdd1000000b003175b760826mr2809290wrs.0.1690907668122; Tue, 01 Aug 2023 09:34:28 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:d100:871b:ec55:67d:5247? (p200300cbc705d100871bec55067d5247.dip0.t-ipconnect.de. [2003:cb:c705:d100:871b:ec55:67d:5247]) by smtp.gmail.com with ESMTPSA id u5-20020a7bc045000000b003fa8dbb7b5dsm14145674wmc.25.2023.08.01.09.34.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Aug 2023 09:34:27 -0700 (PDT) Message-ID: Date: Tue, 1 Aug 2023 18:34:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] fs/proc/kcore: reinstate bounce buffer for KCORE_TEXT regions Content-Language: en-US To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Baoquan He , Uladzislau Rezki , linux-fsdevel@vger.kernel.org, Jiri Olsa , Will Deacon , Mike Galbraith , Mark Rutland , wangkefeng.wang@huawei.com, catalin.marinas@arm.com, ardb@kernel.org, Linux regression tracking , regressions@lists.linux.dev, Matthew Wilcox , Liu Shixin , Jens Axboe , Alexander Viro , stable@vger.kernel.org References: <20230731215021.70911-1-lstoakes@gmail.com> <0af1bc20-8ba2-c6b6-64e6-c1f58d521504@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01.08.23 18:33, Lorenzo Stoakes wrote: > On Tue, Aug 01, 2023 at 11:05:40AM +0200, David Hildenbrand wrote: >> On 31.07.23 23:50, Lorenzo Stoakes wrote: >>> Some architectures do not populate the entire range categorised by >>> KCORE_TEXT, so we must ensure that the kernel address we read from is >>> valid. >>> >>> Unfortunately there is no solution currently available to do so with a >>> purely iterator solution so reinstate the bounce buffer in this instance so >>> we can use copy_from_kernel_nofault() in order to avoid page faults when >>> regions are unmapped. >>> >>> This change partly reverts commit 2e1c0170771e ("fs/proc/kcore: avoid >>> bounce buffer for ktext data"), reinstating the bounce buffer, but adapts >>> the code to continue to use an iterator. >>> >>> Fixes: 2e1c0170771e ("fs/proc/kcore: avoid bounce buffer for ktext data") >>> Reported-by: Jiri Olsa >>> Closes: https://lore.kernel.org/all/ZHc2fm+9daF6cgCE@krava >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Lorenzo Stoakes >>> --- >>> fs/proc/kcore.c | 26 +++++++++++++++++++++++++- >>> 1 file changed, 25 insertions(+), 1 deletion(-) >>> >>> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c >>> index 9cb32e1a78a0..3bc689038232 100644 >>> --- a/fs/proc/kcore.c >>> +++ b/fs/proc/kcore.c >>> @@ -309,6 +309,8 @@ static void append_kcore_note(char *notes, size_t *i, const char *name, >>> static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter) >>> { >>> + struct file *file = iocb->ki_filp; >>> + char *buf = file->private_data; >>> loff_t *fpos = &iocb->ki_pos; >>> size_t phdrs_offset, notes_offset, data_offset; >>> size_t page_offline_frozen = 1; >>> @@ -554,11 +556,22 @@ static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter) >>> fallthrough; >>> case KCORE_VMEMMAP: >>> case KCORE_TEXT: >>> + /* >>> + * Sadly we must use a bounce buffer here to be able to >>> + * make use of copy_from_kernel_nofault(), as these >>> + * memory regions might not always be mapped on all >>> + * architectures. >>> + */ >>> + if (copy_from_kernel_nofault(buf, (void *)start, tsz)) { >>> + if (iov_iter_zero(tsz, iter) != tsz) { >>> + ret = -EFAULT; >>> + goto out; >>> + } >>> /* >>> * We use _copy_to_iter() to bypass usermode hardening >>> * which would otherwise prevent this operation. >>> */ >> >> Having a comment at this indentation level looks for the else case looks >> kind of weird. > > Yeah, but having it indented again would be weird and seem like it doesn't > apply to the block below, there's really no good spot for it and > checkpatch.pl doesn't mind so I think this is ok :) > >> >> (does that comment still apply?) > > Hm good point, actually, now we're using the bounce buffer we don't need to > avoid usermode hardening any more. > > However since we've established a bounce buffer ourselves its still > appropriate to use _copy_to_iter() as we know the source region is good to > copy from. > > To make life easy I'll just respin with an updated comment :) I'm not too picky this time, no need to resend if everybody else is fine :P -- Cheers, David / dhildenb