tcpip/transport/raw: check MTU before copying a buffer from user memory

Reported-by: syzbot+5cccbb7c0511ad1aa175@syzkaller.appspotmail.com
This commit is contained in:
Andrei Vagin
2022-06-09 11:19:00 -07:00
parent 06f7b645e6
commit 6fda48f50d
2 changed files with 8 additions and 0 deletions
@@ -235,6 +235,10 @@ type WriteContext struct {
tos uint8
}
func (c *WriteContext) MTU() uint32 {
return c.route.MTU()
}
// Release releases held resources.
func (c *WriteContext) Release() {
c.route.Release()
+4
View File
@@ -345,6 +345,10 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp
return 0, err
}
if p.Len() > int(ctx.MTU()) {
return 0, &tcpip.ErrMessageTooLong{}
}
// TODO(https://gvisor.dev/issue/6538): Avoid this allocation.
payloadBytes := make([]byte, p.Len())
if _, err := io.ReadFull(p, payloadBytes); err != nil {