netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ptr_ring_unconsume: memory corruption potential?
@ 2025-09-24  3:58 Michael S. Tsirkin
  2025-09-24  4:03 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2025-09-24  3:58 UTC (permalink / raw)
  To: Jason Wang; +Cc: netdev

Jason, guys,
reading ptr ring code, I noticed:


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: ptr_ring_unconsume: memory corruption potential?
  2025-09-24  3:58 ptr_ring_unconsume: memory corruption potential? Michael S. Tsirkin
@ 2025-09-24  4:03 ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2025-09-24  4:03 UTC (permalink / raw)
  To: Jason Wang; +Cc: netdev

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-24  4:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24  3:58 ptr_ring_unconsume: memory corruption potential? Michael S. Tsirkin
2025-09-24  4:03 ` Michael S. Tsirkin

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).