From 621a9d6f15c71caba5f58a9438cb8da2e80c8dc7 Mon Sep 17 00:00:00 2001 From: ShivamKumarJha Date: Thu, 20 Jan 2022 00:24:51 +0530 Subject: [PATCH] Add net/ modifications Signed-off-by: ShivamKumarJha --- net/core/filter.c | 13 +++++++++++++ net/ipv4/netfilter/arp_tables.c | 3 ++- net/ipv4/netfilter/ip_tables.c | 3 ++- net/ipv4/udp.c | 13 +++++++++++++ net/ipv6/netfilter/ip6_tables.c | 3 ++- net/qrtr/qrtr.c | 14 ++++++++++++++ net/qrtr/qrtr.h | 3 +++ 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index aff14a883ffd..947866bc4834 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -8356,6 +8356,19 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, case offsetof(struct bpf_sock_ops, sk): SOCK_OPS_GET_SK(); break; + // XIAOMI: Add by zholei8 --start + case offsetof(struct bpf_sock_ops, sk_uid): + SOCK_OPS_GET_FIELD(sk_uid, sk_uid, struct sock); + break; + + case offsetof(struct bpf_sock_ops, voip_daddr): + SOCK_OPS_GET_FIELD(voip_daddr, sk_daddr, struct sock); + break; + + case offsetof(struct bpf_sock_ops, voip_dport): + SOCK_OPS_GET_FIELD(voip_dport, sk_dport, struct sock); + break; + // XIAOMI: Add by zholei8 --end } return insn - insn_buf; } diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index 8a6a4384e791..0b76c1f9bbb7 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -7,6 +7,7 @@ * Some ARP specific bits are: * * Copyright (C) 2002 David S. Miller (davem@redhat.com) + * Copyright (C) 2021 XiaoMi, Inc. * Copyright (C) 2006-2009 Patrick McHardy * */ @@ -1406,7 +1407,7 @@ static int compat_get_entries(struct net *net, xt_compat_lock(NFPROTO_ARP); t = xt_find_table_lock(net, NFPROTO_ARP, get.name); if (!IS_ERR(t)) { - const struct xt_table_info *private = t->private; + const struct xt_table_info *private = xt_table_get_private_protected(t); struct xt_table_info info; ret = compat_table_info(private, &info); diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index 485276999544..c991b6936bb7 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c @@ -3,6 +3,7 @@ * Packet matching code. * * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling + * Copyright (C) 2021 XiaoMi, Inc. * Copyright (C) 2000-2005 Netfilter Core Team * Copyright (C) 2006-2010 Patrick McHardy */ @@ -1616,7 +1617,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr, xt_compat_lock(AF_INET); t = xt_find_table_lock(net, AF_INET, get.name); if (!IS_ERR(t)) { - const struct xt_table_info *private = t->private; + const struct xt_table_info *private = xt_table_get_private_protected(t); struct xt_table_info info; ret = compat_table_info(private, &info); if (!ret && get.size == info.size) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index d89725d93d6c..0dede82b243a 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -985,6 +985,10 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); struct sk_buff *skb; struct ip_options_data opt_copy; + // xiaomi add by zhoulei8 --start + __be16 tmp_dport; + __be32 tmp_daddr; + // xiaomi add by zhoulei8 --end if (len > 0xFFFF) return -EMSGSIZE; @@ -1029,6 +1033,15 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) daddr = usin->sin_addr.s_addr; dport = usin->sin_port; + // xiaomi add by zhoulei8 --start + tmp_dport = sk->sk_dport; + tmp_daddr = sk->sk_daddr; + sk->sk_dport = dport; + sk->sk_daddr = daddr; + udp_state_bpf(sk); + sk->sk_dport = tmp_dport; + sk->sk_daddr = tmp_daddr; + // xiaomi add by zhoulei8 --end if (dport == 0) return -EINVAL; } else { diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 12735ee7713a..8a85621090e7 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -3,6 +3,7 @@ * Packet matching code. * * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling + * Copyright (C) 2021 XiaoMi, Inc. * Copyright (C) 2000-2005 Netfilter Core Team * Copyright (c) 2006-2010 Patrick McHardy */ @@ -1625,7 +1626,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr, xt_compat_lock(AF_INET6); t = xt_find_table_lock(net, AF_INET6, get.name); if (!IS_ERR(t)) { - const struct xt_table_info *private = t->private; + const struct xt_table_info *private = xt_table_get_private_protected(t); struct xt_table_info info; ret = compat_table_info(private, &info); if (!ret && get.size == info.size) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index d5f77efbd149..6246efe279e6 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2015, Sony Mobile Communications Inc. + * Copyright (C) 2021 XiaoMi, Inc. * Copyright (c) 2013, 2018-2019 The Linux Foundation. All rights reserved. */ #include @@ -22,8 +23,21 @@ #include "qrtr.h" #define QRTR_LOG_PAGE_CNT 4 + +#ifdef CONFIG_DEBUG_POWER_MI +#define QRTR_INFO(ctx, x, ...) \ + do { \ + ipc_log_string(ctx, x, ##__VA_ARGS__); \ + if (qrtr_first_msg) \ + { \ + qrtr_first_msg = 0; \ + pr_info(x, ##__VA_ARGS__); \ + } \ + }while(0) +#else #define QRTR_INFO(ctx, x, ...) \ ipc_log_string(ctx, x, ##__VA_ARGS__) +#endif #define QRTR_PROTO_VER_1 1 #define QRTR_PROTO_VER_2 3 diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h index fba24c530146..c2a35508874b 100644 --- a/net/qrtr/qrtr.h +++ b/net/qrtr/qrtr.h @@ -4,6 +4,9 @@ #include +#ifdef CONFIG_DEBUG_POWER_MI +extern int qrtr_first_msg; +#endif struct sk_buff; /* endpoint node id auto assignment */