Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5529445rwb; Tue, 1 Aug 2023 04:16:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHKKp3RvR6Ui4XA+C8YP+PiJ9J4S1eYhFeBq/GnQNaFLp8UqvqEQTSd0O5YG6xVAeP0klTT X-Received: by 2002:a17:90b:224d:b0:262:fa59:2908 with SMTP id hk13-20020a17090b224d00b00262fa592908mr15265503pjb.1.1690888594000; Tue, 01 Aug 2023 04:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690888593; cv=none; d=google.com; s=arc-20160816; b=ig5Dy3VC2y2soKkjacg7t95/+or1QQbwOw1McGrLSaU0BnWocSL/GVVEHHgsgvtpAW fPf3oxYS9n7IQLf/+qqh0IajVmTDnam0wXVyhQD3vhFDWjSxHeQk3LvdsKurD7YNEdVE n39omOyVNPpx/GpdN5LgWzUW3tjWGTOTbGYWY9J/mTG432eGbTPj9pQrn/K52tnqbD6W mnMWKgOpAdiU1r/LS6CBr+8AQztxBcO0EWXl822P4kQYL4wr/ac/WTE+Q1lsM1s+DouJ mANvFim07GZjeTGiS19HDlmTVncbB+bjXoQWWtqng5+RoiAJ38DGCvDn2mYbuhBKx+wM mYeA== 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:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=n9kdFDWcMyK/1HOobM9v5phnyHdEWyzyFaqhLZWLocA=; fh=U7RXjLx6d9C1qXILINLg/viat5lsLe/rlNb9XtyQXkk=; b=WLBhHPDND/b3k4uCbT4Tx9h5rqc1AnKrrpCramoTQaqOwZ3X+VEuxwXvxW75ofyNGz p/VGbTJgx5hlNLhk/ThvXlBQVNIIR45UIcuxNCZQkMPaBCigFAgGxu96eKE0dJpqol8Q j/xYT9Owy4/oMQ/NEfc4LkZQMOE2JEFZdz73WZA6u2cE6YlUJZSSkI5QaVMU4KBKSLPz 8UFIaR+lz6ThbJaUvqQgPXk7qyl6EBZWePYjBA5r1lzXuoKENznZAERitb40yvPSUO6x 99pArkgm2lEljeCF87GNdUIpt2xdIjoVbnIpvlffVvGbRjf+O6DD3/Opj5H6XBH7tDB2 FBaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K9ODMQ0i; 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 d23-20020a63f257000000b00553b02a9a1asi8502688pgk.249.2023.08.01.04.16.21; Tue, 01 Aug 2023 04:16:33 -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=K9ODMQ0i; 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 S232361AbjHAJOU (ORCPT + 99 others); Tue, 1 Aug 2023 05:14:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233237AbjHAJNj (ORCPT ); Tue, 1 Aug 2023 05:13:39 -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 D87F855B8 for ; Tue, 1 Aug 2023 02:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690880941; 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=n9kdFDWcMyK/1HOobM9v5phnyHdEWyzyFaqhLZWLocA=; b=K9ODMQ0iZGpQPBrlQQz49Ql1kw9ompu+7Pcoy9RWrFYoQHyZfEk2I1GphxrDvv+9u7DB6K zdvOD2DMaRcSldAjETs7X0bIlkCSVfWtof00SiJlEp4umBSd1uirC0rH9iW2YOOksw7kR8 Zn2XLK1/ed8qs7xNRSAkvGe4Na13H30= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-BZTBZYzPOsmZAW3u822xmQ-1; Tue, 01 Aug 2023 05:05:43 -0400 X-MC-Unique: BZTBZYzPOsmZAW3u822xmQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fd2dec82b7so31962805e9.2 for ; Tue, 01 Aug 2023 02:05:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880742; x=1691485542; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=n9kdFDWcMyK/1HOobM9v5phnyHdEWyzyFaqhLZWLocA=; b=ltXr9q196UFkINIFu6IqWwrlLrFU0WlQbJo37I70R66JHu9QiNoIRUf2/zNd6Gh0Uv WC3VLRuMuCHw0M90k8BNZbpQBNhO8lFjgxjqumBQoiyjRwNTZqv0re0/Cf24PA6N6R0R 1ceGl0Yuwhfv25AnzP+XqccEHZ8+jJc2WRQABXWYnwgcQGCquwtCUlrcEuZCVsIWVB4m 2cHthMcHncvo9sC+ipltz+L8ZthdmOcdVD1fjiEjMkK4DqB8E1kg5jTn1PoSIXdDAjnm +NbrQuWvVJ+G4Cx9aoumG9F5rf0FcYKNhGcJ5R1JA7UYMPhqQZ+r+TGSXoX05HiESeiq AwUg== X-Gm-Message-State: ABy/qLYN0cQ5SGvB+1eTWTjzIiEwcpk7sgKeUe2VcJuiz+1Cn1Pg4Jwb rP2OlDolhYCDNKd3YEI5xvJNeDsivVAwQB7BbEHFKPuU8CG8HbCwltEwfhdrhZjEAVh+Juo3GId raDGCY+MUjm0Szm0nhfd1U92W X-Received: by 2002:a7b:ce16:0:b0:3fc:521:8492 with SMTP id m22-20020a7bce16000000b003fc05218492mr1796100wmc.5.1690880742247; Tue, 01 Aug 2023 02:05:42 -0700 (PDT) X-Received: by 2002:a7b:ce16:0:b0:3fc:521:8492 with SMTP id m22-20020a7bce16000000b003fc05218492mr1796077wmc.5.1690880741870; Tue, 01 Aug 2023 02:05:41 -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 f17-20020adffcd1000000b00313f61889ecsm15587910wrs.66.2023.08.01.02.05.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Aug 2023 02:05:41 -0700 (PDT) Message-ID: <0af1bc20-8ba2-c6b6-64e6-c1f58d521504@redhat.com> Date: Tue, 1 Aug 2023 11:05:40 +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 To: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: 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> Content-Language: en-US From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230731215021.70911-1-lstoakes@gmail.com> 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 autolearn=unavailable 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 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. (does that comment still apply?) -- Cheers, David / dhildenb