Don't return empty translation in ring buffer during bus error.

Reported-by: syzbot+b441fb97dc83729a444d@syzkaller.appspotmail.com
PiperOrigin-RevId: 726111936
This commit is contained in:
Lucas Manning
2025-02-12 10:43:52 -08:00
committed by gVisor bot
parent 8555758760
commit 95ad423f8c
2 changed files with 11 additions and 12 deletions
@@ -338,9 +338,7 @@ func (m *Endpoint) Translate(ctx context.Context, required, optional memmap.Mapp
var err error
if m.mode&rxRingBuffer != 0 {
var rxTranslation memmap.Translation
rxTranslation, err = m.rxRingBuffer.Translate(ctx, required, optional, at)
ts = append(ts, rxTranslation)
ts, err = m.rxRingBuffer.AppendTranslation(ctx, required, optional, at, ts)
}
if m.mode&txRingBuffer != 0 {
// Translate went outside the bounds of the RX ring buffer, which is valid
@@ -351,9 +349,7 @@ func (m *Endpoint) Translate(ctx context.Context, required, optional memmap.Mapp
optional.Start = ts[len(ts)-1].Source.End
}
}
var txTranslation memmap.Translation
txTranslation, err = m.txRingBuffer.Translate(ctx, required, optional, at)
ts = append(ts, txTranslation)
ts, err = m.txRingBuffer.AppendTranslation(ctx, required, optional, at, ts)
}
return ts, err
}
@@ -49,7 +49,8 @@ type ringBuffer struct {
size uint64
// +checklocks:dataMu
mapping memmap.MappableRange
data memmap.FileRange
// +checklocks:dataMu
data memmap.FileRange
mf *pgalloc.MemoryFile `state:"nosave"`
}
@@ -94,14 +95,16 @@ func (rb *ringBuffer) destroy() {
*rb = ringBuffer{}
}
// Translate implements memmap.Mappable.Translate.
func (rb *ringBuffer) Translate(ctx context.Context, required, optional memmap.MappableRange, at hostarch.AccessType) (memmap.Translation, error) {
// AppendTranslation essentially implements memmap.Mappable.Translate, with the
// only difference being that it takes in a slice of translations and appends
// this ring buffer's translation.
func (rb *ringBuffer) AppendTranslation(ctx context.Context, required, optional memmap.MappableRange, at hostarch.AccessType, ts []memmap.Translation) ([]memmap.Translation, error) {
rb.dataMu.Lock()
defer rb.dataMu.Unlock()
var beyondEOF bool
if required.End > rb.size {
if required.Start >= rb.size {
return memmap.Translation{}, &memmap.BusError{Err: io.EOF}
return ts, &memmap.BusError{Err: io.EOF}
}
beyondEOF = true
required.End = rb.size
@@ -110,12 +113,12 @@ func (rb *ringBuffer) Translate(ctx context.Context, required, optional memmap.M
optional.End = rb.size
}
mappableRange := rb.mapping.Intersect(optional)
ts := memmap.Translation{
ts = append(ts, memmap.Translation{
Source: mappableRange,
File: rb.mf,
Offset: rb.data.Start + (mappableRange.Start - rb.mapping.Start),
Perms: hostarch.AnyAccess,
}
})
if beyondEOF {
return ts, &memmap.BusError{Err: io.EOF}
}