From: Andrew Morton <akpm@linux-foundation.org>
To: Jakob Koschel <jakobkoschel@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>,
David Hildenbrand <david@redhat.com>,
Oscar Salvador <osalvador@suse.de>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>
Subject: Re: [PATCH] fs/proc/kcore.c: remove check of list iterator against head past the loop body
Date: Thu, 31 Mar 2022 16:48:43 -0700 [thread overview]
Message-ID: <20220331164843.b531fbf00d6e7afd6cdfe113@linux-foundation.org> (raw)
In-Reply-To: <20220331223700.902556-1-jakobkoschel@gmail.com>
On Fri, 1 Apr 2022 00:37:00 +0200 Jakob Koschel <jakobkoschel@gmail.com> wrote:
> 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.
>
> 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 == head, using the iterator variable after the loop should
> be avoided.
>
> 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].
>
> ...
>
Speaking of limiting scope...
--- a/fs/proc/kcore.c~fs-proc-kcorec-remove-check-of-list-iterator-against-head-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 = 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 >= m->addr + m->size) {
+ struct kcore_list *iter;
+
m = NULL;
list_for_each_entry(iter, &kclist_head, list) {
if (start >= iter->addr &&
_
next prev parent reply other threads:[~2022-03-31 23:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 22:37 Jakob Koschel
2022-03-31 23:48 ` Andrew Morton [this message]
2022-04-01 7:19 ` Jakob Koschel
2022-04-04 22:55 ` Andrew Morton
2022-04-05 8:48 ` Jakob Koschel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220331164843.b531fbf00d6e7afd6cdfe113@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bjohannesmeyer@gmail.com \
--cc=c.giuffrida@vu.nl \
--cc=david@redhat.com \
--cc=h.j.bos@vu.nl \
--cc=jakobkoschel@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=osalvador@suse.de \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®