Netstack: Check address matches the endpoint protocol for IP_DROP_MEMBERSHIP

According to syzkaller report, the setsockopt option used was 0x24, which
matches with IP_DROP_MEMBERSHIP for which we did not have the equivalent check
that we had for IP_ADD_MEMBERSHIP.

Reported-by: syzbot+923097b958e5b74950d1@syzkaller.appspotmail.com
PiperOrigin-RevId: 487840922
This commit is contained in:
Konstantin Bogomolov
2022-11-11 09:20:04 -08:00
committed by gVisor bot
parent 5a0803c66e
commit 8756ebc3b4
2 changed files with 7 additions and 2 deletions
@@ -817,11 +817,16 @@ func TestMismatchedMulticastAddressAndProtocol(t *testing.T) {
InterfaceAddr: utils.Ipv4Addr.Address,
}
// Add membership should succeed when the interface index is specified,
// Add/remove membership should succeed when the interface index is specified,
// even if a bad interface address is specified.
addOpt := tcpip.AddMembershipOption(memOpt)
expErr := &tcpip.ErrInvalidOptionValue{}
if err := ep.SetSockOpt(&addOpt); err != expErr {
t.Fatalf("ep.SetSockOpt(&%#v): want %q, got %q", addOpt, expErr, err)
}
removeOpt := tcpip.RemoveMembershipOption(memOpt)
if err := ep.SetSockOpt(&removeOpt); err != expErr {
t.Fatalf("ep.SetSockOpt(&%#v): want %q, got %q", addOpt, expErr, err)
}
}
@@ -951,7 +951,7 @@ func (e *Endpoint) SetSockOpt(opt tcpip.SettableSocketOption) tcpip.Error {
e.multicastMemberships[memToInsert] = struct{}{}
case *tcpip.RemoveMembershipOption:
if !header.IsV4MulticastAddress(v.MulticastAddr) && !header.IsV6MulticastAddress(v.MulticastAddr) {
if !(header.IsV4MulticastAddress(v.MulticastAddr) && e.netProto == header.IPv4ProtocolNumber) && !(header.IsV6MulticastAddress(v.MulticastAddr) && e.netProto == header.IPv6ProtocolNumber) {
return &tcpip.ErrInvalidOptionValue{}
}