mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
loader/elf: validate file offset
Reported-by: syzbot+7406eef8247cb5a20855@syzkaller.appspotmail.com PiperOrigin-RevId: 337974474
This commit is contained in:
@@ -194,6 +194,10 @@ func parseHeader(ctx context.Context, f fullReader) (elfInfo, error) {
|
||||
log.Infof("Too many phdrs (%d): total size %d > %d", hdr.Phnum, totalPhdrSize, maxTotalPhdrSize)
|
||||
return elfInfo{}, syserror.ENOEXEC
|
||||
}
|
||||
if int64(hdr.Phoff) < 0 || int64(hdr.Phoff+uint64(totalPhdrSize)) < 0 {
|
||||
ctx.Infof("Unsupported phdr offset %d", hdr.Phoff)
|
||||
return elfInfo{}, syserror.ENOEXEC
|
||||
}
|
||||
|
||||
phdrBuf := make([]byte, totalPhdrSize)
|
||||
_, err = f.ReadFull(ctx, usermem.BytesIOSequence(phdrBuf), int64(hdr.Phoff))
|
||||
@@ -437,6 +441,10 @@ func loadParsedELF(ctx context.Context, m *mm.MemoryManager, f fsbridge.File, in
|
||||
ctx.Infof("PT_INTERP path too big: %v", phdr.Filesz)
|
||||
return loadedELF{}, syserror.ENOEXEC
|
||||
}
|
||||
if int64(phdr.Off) < 0 || int64(phdr.Off+phdr.Filesz) < 0 {
|
||||
ctx.Infof("Unsupported PT_INTERP offset %d", phdr.Off)
|
||||
return loadedELF{}, syserror.ENOEXEC
|
||||
}
|
||||
|
||||
path := make([]byte, phdr.Filesz)
|
||||
_, err := f.ReadFull(ctx, usermem.BytesIOSequence(path), int64(phdr.Off))
|
||||
|
||||
Reference in New Issue
Block a user