BACKPORT net: Fix use after free by removing length arg from sk_data_ready callbacks.
authorDavid S. Miller <davem@davemloft.net>
Fri, 11 Apr 2014 20:15:36 +0000 (16:15 -0400)
committerDanny Wood <danwood76@gmail.com>
Thu, 15 Jul 2021 09:45:36 +0000 (10:45 +0100)
commitb3ac109f9084c12223564e244fb3f85b5305f4b4
tree512a0764c385ed7185e0ad0247dc8ef1c64e5a87
parentc67803c60b3aa4337b790760b978b648e1aac3c3
BACKPORT net: Fix use after free by removing length arg from sk_data_ready callbacks.

Several spots in the kernel perform a sequence like:

skb_queue_tail(&sk->s_receive_queue, skb);
sk->sk_data_ready(sk, skb->len);

But at the moment we place the SKB onto the socket receive queue it
can be consumed and freed up.  So this skb->len access is potentially
to freed up memory.

Furthermore, the skb->len can be modified by the consumer so it is
possible that the value isn't accurate.

And finally, no actual implementation of this callback actually uses
the length argument.  And since nobody actually cared about it's
value, lots of call sites pass arbitrary values in such as '0' and
even '1'.

So just remove the length argument from the callback, that way there
is no confusion whatsoever and all of these use-after-free cases get
fixed as a side effect.

Based upon a patch by Eric Dumazet and his suggestion to audit this
issue tree-wide.

Change-Id: Ia7443b38da20849b684957049812805ff25ab1f0
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: elektroschmock <elektroschmock78@googlemail.com>
54 files changed:
drivers/scsi/iscsi_tcp.c
drivers/scsi/iscsi_tcp.h
fs/dlm/lowcomms.c
fs/ncpfs/ncp_fs_sb.h
fs/ncpfs/sock.c
fs/ocfs2/cluster/tcp.c
fs/ocfs2/cluster/tcp_internal.h
include/linux/sunrpc/svcsock.h
include/net/sctp/sctp.h
include/net/sock.h
net/atm/clip.c
net/atm/lec.c
net/atm/mpc.c
net/atm/raw.c
net/atm/signaling.c
net/ax25/ax25_in.c
net/bluetooth/l2cap_sock.c
net/bluetooth/rfcomm/core.c
net/bluetooth/rfcomm/sock.c
net/bluetooth/sco.c
net/caif/caif_socket.c
net/ceph/messenger.c
net/core/skbuff.c
net/core/sock.c
net/dccp/input.c
net/dccp/minisocks.c
net/decnet/dn_nsp_in.c
net/ipv4/tcp_input.c
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_minisocks.c
net/iucv/af_iucv.c
net/key/af_key.c
net/netlink/af_netlink.c
net/netrom/af_netrom.c
net/nfc/llcp_core.c
net/packet/af_packet.c
net/phonet/pep-gprs.c
net/phonet/pep.c
net/rds/tcp.h
net/rds/tcp_listen.c
net/rds/tcp_recv.c
net/rose/af_rose.c
net/rxrpc/ar-input.c
net/rxrpc/ar-internal.h
net/sctp/socket.c
net/sctp/ulpqueue.c
net/sunrpc/svcsock.c
net/sunrpc/xprtsock.c
net/tipc/socket.c
net/unix/af_unix.c
net/vmw_vsock/vmci_transport_notify.c
net/vmw_vsock/vmci_transport_notify_qstate.c
net/x25/af_x25.c
net/x25/x25_in.c