Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1369575pxb; Fri, 1 Apr 2022 11:27:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd4iNQiJDAm7+N8u2SqgbhVrQa9M/kgtIrI1kom/CnDqKLQF2uvI8Xdu5Treyc9GANQP9b X-Received: by 2002:a17:90b:4c8e:b0:1c6:d1ed:f6b2 with SMTP id my14-20020a17090b4c8e00b001c6d1edf6b2mr13087980pjb.166.1648837668675; Fri, 01 Apr 2022 11:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648837668; cv=none; d=google.com; s=arc-20160816; b=uZCDL3oK6iRnMlhMbFzGZCIjBxeXa1MB5xGytf0sTzZOsT3q+PHk2Nd83rB/RM31JN 3bGejGujFuV13jB6icR9jC7K+L7tfndjKKEefaOPparYajGRwMbZ+iuAX74EyU9mIc08 lBqUgc4Y82WztdQYOQCZWRb1NssS8V7AxNH91dMavtfskTUlwnqzBYtMIUOYM3L5pV3V 6CjGl6RlVgakD6rsw7A1eB4KuZj2RrhibSUiZ7H69KmKTRZgp/6LTo1PUaF4fbnsM2g3 oA6VCZOCP1qHIspGsSqUVluKDDJHMpqae8as6OsatyOxmPIIvwRIQkwspZZi7b+m7BuC JeOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=ubG9Vku/N0fiy/2SLaUSFTnlDKcWy9tp5aypQ1g0yR0=; b=b4ieoJYliW0vW/FKel8JAH+bj1XGc2myy32DDCkdwQqaMsuhrjEipcLYSfJyecjKlm IN/kRLRE5EUEDY2mvXYuVz7DTXB2Q11OrcHsAYXvoRVv69NjpaG4IlPwmzA0hLB+7q// T49KAW6GeIOITOmGws2FlXet7FNAaSOPfRev5hDuRgf87+RSjaRzLkUsL/xvmMkS71KQ d5C+GLvNnRl0r052206c4IWVqyChnwd6XZM6U4ob5zeOKSqhMDGHPAMIa/e83OfiyQnW oer3xlE9HpKpX7K53FJAxBYH+uEWN1+3pB+yJLupnitBqVE5Q8my659r7HJtDu1kz6rR 8Ajw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qeR+po4x; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m70-20020a633f49000000b003816cf0661dsi3235584pga.363.2022.04.01.11.27.32; Fri, 01 Apr 2022 11:27:48 -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=@gmail.com header.s=20210112 header.b=qeR+po4x; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343823AbiDAHVv (ORCPT + 99 others); Fri, 1 Apr 2022 03:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239717AbiDAHVu (ORCPT ); Fri, 1 Apr 2022 03:21:50 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DC41E0D8; Fri, 1 Apr 2022 00:20:00 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id w25so1863164edi.11; Fri, 01 Apr 2022 00:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ubG9Vku/N0fiy/2SLaUSFTnlDKcWy9tp5aypQ1g0yR0=; b=qeR+po4xuMTE7NT42VMHjZFG4pDnrmbTx3qLmihDu198PJkosJh+2LD7Gm2agZ/6/n Rh3REosbufMhaAtMz8tJ7FJD9RXIA6FjTXHFkvPf/Z6gNdOZGDbLGLUm6VBhWieFruzF 0QICo8ryhdAlaxL4mVBgaFRru05eQXUNP56zdgCWX+jyFvcSR0SqPgu3hwF3OEsvOrfe w8DIfnGKoCj96ldnimavctFqxewc0rMfhOrGP6p7JHQD2kfKL3cyTRZF7nOcGy+O6+fX P96Ni3tAi0wo+RBJkZZ5UDX0J9fYCuJTnFTeUWhOulbpDpF/qiq+qgTNo11gwWz/ZnMS 4vXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ubG9Vku/N0fiy/2SLaUSFTnlDKcWy9tp5aypQ1g0yR0=; b=EXT9/EFYTXqQCXej9j49Zbx4EEHgRpDaLoWqaPeK3yt2KV1hs9RjNJ0hZtalsz4hYC Wt3he//cwI7Kp+S1ejCjZAkZaFzFbquQCpp5iwp+ejRJp1YlFGuikzrBNFnZg3ItXTAS hGHPr9MOt6NQ3qljauS1pNBqr9PV1BS6KMWO3ELYUYcBnwEyKvYIT79W4Kt9Ea6OHJUx MXcCnOsR1031BfEqHqasdaUqQRnyfmxclSjiVhxjjHeOgHKOKheTZVJxMdggu6x8+oQJ 7IVRW8N3xi0nbJKLpqezab12XkyfP6irZxpLHpj/75GZSEF3/sX/RXMb6IgatpJcHc/7 HL8Q== X-Gm-Message-State: AOAM531qFMZkvBRIescTHStT2fEYtDhE7TcTgUjBrTkiiS+BkQ3PZt5I AOo/uxHJVPxy19AwghKPD3XEwUNkDfD2zKMO X-Received: by 2002:a05:6402:42d4:b0:412:c26b:789 with SMTP id i20-20020a05640242d400b00412c26b0789mr19840232edc.232.1648797598835; Fri, 01 Apr 2022 00:19:58 -0700 (PDT) Received: from smtpclient.apple (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.gmail.com with ESMTPSA id s14-20020aa7cb0e000000b00410bf015567sm782154edt.92.2022.04.01.00.19.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Apr 2022 00:19:58 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: [PATCH] fs/proc/kcore.c: remove check of list iterator against head past the loop body From: Jakob Koschel In-Reply-To: <20220331164843.b531fbf00d6e7afd6cdfe113@linux-foundation.org> Date: Fri, 1 Apr 2022 09:19:57 +0200 Cc: Mike Rapoport , David Hildenbrand , Oscar Salvador , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Content-Transfer-Encoding: quoted-printable Message-Id: References: <20220331223700.902556-1-jakobkoschel@gmail.com> <20220331164843.b531fbf00d6e7afd6cdfe113@linux-foundation.org> To: Andrew Morton X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 1. Apr 2022, at 01:48, Andrew Morton = wrote: >=20 > On Fri, 1 Apr 2022 00:37:00 +0200 Jakob Koschel = wrote: >=20 >> When list_for_each_entry() completes the iteration over the whole = list >> without breaking the loop, the iterator value will be a bogus pointer >> computed based on the head element. >>=20 >> While it is safe to use the pointer to determine if it was computed >> based on the head element, either with list_entry_is_head() or >> &pos->member =3D=3D head, using the iterator variable after the loop = should >> be avoided. >>=20 >> In preparation to limit the scope of a list iterator to the list >> traversal loop, use a dedicated pointer to point to the found element = [1]. >>=20 >> ... >>=20 >=20 > Speaking of limiting scope... Fair point :-) I see you have applied this already to the -mm tree. Shall I still move = the iterator? The hope is to remove the 'iter' variable altogether when there are no = uses after the loop anymore. >=20 > --- = a/fs/proc/kcore.c~fs-proc-kcorec-remove-check-of-list-iterator-against-hea= d-past-the-loop-body-fix > +++ a/fs/proc/kcore.c > @@ -316,7 +316,6 @@ read_kcore(struct file *file, char __use > size_t page_offline_frozen =3D 1; > size_t phdrs_len, notes_len; > struct kcore_list *m; > - struct kcore_list *iter; > size_t tsz; > int nphdr; > unsigned long start; > @@ -480,6 +479,8 @@ read_kcore(struct file *file, char __use > * the previous entry, search for a matching entry. > */ > if (!m || start < m->addr || start >=3D m->addr + = m->size) { > + struct kcore_list *iter; > + > m =3D NULL; > list_for_each_entry(iter, &kclist_head, list) { > if (start >=3D iter->addr && > _ >=20 Jakob=