From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: netdev@vger.kernel.org
Subject: Re: ptr_ring_unconsume: memory corruption potential?
Date: Wed, 24 Sep 2025 00:03:39 -0400 [thread overview]
Message-ID: <20250924000311-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20250923235611-mutt-send-email-mst@kernel.org>
On Tue, Sep 23, 2025 at 11:58:40PM -0400, Michael S. Tsirkin wrote:
> Jason, guys,
> reading ptr ring code, I noticed:
>
Pls ignore. ENOTENOUGHCOFFEE. It's a nop.
> static inline void ptr_ring_unconsume(struct ptr_ring *r, void **batch, int n,
> void (*destroy)(void *))
> {
> unsigned long flags;
> int head;
>
> spin_lock_irqsave(&r->consumer_lock, flags);
> spin_lock(&r->producer_lock);
>
> if (!r->size)
> goto done;
>
> /*
> * Clean out buffered entries (for simplicity). This way following code
> * can test entries for NULL and if not assume they are valid.
> */
> head = r->consumer_head - 1;
> while (likely(head >= r->consumer_tail))
> r->queue[head--] = NULL;
> __ptr_ring_update(r, head);
> r->consumer_tail = r->consumer_head;
>
>
> ...
>
>
>
> Does not look like this will DTRT if r->consumer_head == 0 .
> In fact it looks like it will go off corrupting memory.
>
> Why isn't this a concern?
>
> --
> MST
prev parent reply other threads:[~2025-09-24 4:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 3:58 ptr_ring_unconsume: memory corruption potential? Michael S. Tsirkin
2025-09-24 4:03 ` Michael S. Tsirkin [this message]
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=20250924000311-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=jasowang@redhat.com \
--cc=netdev@vger.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;
as well as URLs for NNTP newsgroup(s).