mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 13:41:30 +00:00
packet: compat support for sock_fprog
Socket option PACKET_FANOUT_DATA takes a struct sock_fprog as argument
if PACKET_FANOUT has mode PACKET_FANOUT_CBPF. This structure contains
a pointer into user memory. If userland is 32-bit and kernel is 64-bit
the two disagree about the layout of struct sock_fprog.
Add compat setsockopt support to convert a 32-bit compat_sock_fprog to
a 64-bit sock_fprog. This is analogous to compat_sock_fprog support for
SO_REUSEPORT added in commit 1957598840
("soreuseport: add compat
case for setsockopt SO_ATTACH_REUSEPORT_CBPF").
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ca8bdaf13a
commit
719c44d340
3 changed files with 41 additions and 2 deletions
|
@ -93,6 +93,7 @@
|
|||
#include <net/inet_common.h>
|
||||
#endif
|
||||
#include <linux/bpf.h>
|
||||
#include <net/compat.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
@ -3940,6 +3941,27 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
|
|||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
static int compat_packet_setsockopt(struct socket *sock, int level, int optname,
|
||||
char __user *optval, unsigned int optlen)
|
||||
{
|
||||
struct packet_sock *po = pkt_sk(sock->sk);
|
||||
|
||||
if (level != SOL_PACKET)
|
||||
return -ENOPROTOOPT;
|
||||
|
||||
if (optname == PACKET_FANOUT_DATA &&
|
||||
po->fanout && po->fanout->type == PACKET_FANOUT_CBPF) {
|
||||
optval = (char __user *)get_compat_bpf_fprog(optval);
|
||||
if (!optval)
|
||||
return -EFAULT;
|
||||
optlen = sizeof(struct sock_fprog);
|
||||
}
|
||||
|
||||
return packet_setsockopt(sock, level, optname, optval, optlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int packet_notifier(struct notifier_block *this,
|
||||
unsigned long msg, void *ptr)
|
||||
{
|
||||
|
@ -4416,6 +4438,9 @@ static const struct proto_ops packet_ops = {
|
|||
.shutdown = sock_no_shutdown,
|
||||
.setsockopt = packet_setsockopt,
|
||||
.getsockopt = packet_getsockopt,
|
||||
#ifdef CONFIG_COMPAT
|
||||
.compat_setsockopt = compat_packet_setsockopt,
|
||||
#endif
|
||||
.sendmsg = packet_sendmsg,
|
||||
.recvmsg = packet_recvmsg,
|
||||
.mmap = packet_mmap,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue