Skip to content

Commit

Permalink
Revert "net: core: Support UID-based routing."
Browse files Browse the repository at this point in the history
This reverts commit 99a6ea4.

Bug: 16355602
Change-Id: I7d75b52d8863e932707daf391892480542c2e965
  • Loading branch information
lcolitti committed Dec 14, 2016
1 parent 9e17a9f commit a11e5dc
Show file tree
Hide file tree
Showing 29 changed files with 26 additions and 129 deletions.
6 changes: 1 addition & 5 deletions include/net/fib_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ struct fib_rule {
struct fib_rule __rcu *ctarget;
char iifname[IFNAMSIZ];
char oifname[IFNAMSIZ];
kuid_t uid_start;
kuid_t uid_end;
struct rcu_head rcu;
struct net * fr_net;
};
Expand Down Expand Up @@ -82,9 +80,7 @@ struct fib_rules_ops {
[FRA_FWMARK] = { .type = NLA_U32 }, \
[FRA_FWMASK] = { .type = NLA_U32 }, \
[FRA_TABLE] = { .type = NLA_U32 }, \
[FRA_GOTO] = { .type = NLA_U32 }, \
[FRA_UID_START] = { .type = NLA_U32 }, \
[FRA_UID_END] = { .type = NLA_U32 }
[FRA_GOTO] = { .type = NLA_U32 }

static inline void fib_rule_get(struct fib_rule *rule)
{
Expand Down
9 changes: 1 addition & 8 deletions include/net/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <linux/socket.h>
#include <linux/in6.h>
#include <linux/atomic.h>
#include <linux/uidgid.h>

/*
* ifindex generation is per-net namespace, and loopback is
Expand All @@ -32,7 +31,6 @@ struct flowi_common {
#define FLOWI_FLAG_CAN_SLEEP 0x02
#define FLOWI_FLAG_KNOWN_NH 0x04
__u32 flowic_secid;
kuid_t flowic_uid;
};

union flowi_uli {
Expand Down Expand Up @@ -69,7 +67,6 @@ struct flowi4 {
#define flowi4_proto __fl_common.flowic_proto
#define flowi4_flags __fl_common.flowic_flags
#define flowi4_secid __fl_common.flowic_secid
#define flowi4_uid __fl_common.flowic_uid

/* (saddr,daddr) must be grouped, same order as in IP header */
__be32 saddr;
Expand All @@ -89,8 +86,7 @@ static inline void flowi4_init_output(struct flowi4 *fl4, int oif,
__u32 mark, __u8 tos, __u8 scope,
__u8 proto, __u8 flags,
__be32 daddr, __be32 saddr,
__be16 dport, __be16 sport,
kuid_t uid)
__be16 dport, __be16 sport)
{
fl4->flowi4_oif = oif;
fl4->flowi4_iif = LOOPBACK_IFINDEX;
Expand All @@ -100,7 +96,6 @@ static inline void flowi4_init_output(struct flowi4 *fl4, int oif,
fl4->flowi4_proto = proto;
fl4->flowi4_flags = flags;
fl4->flowi4_secid = 0;
fl4->flowi4_uid = uid;
fl4->daddr = daddr;
fl4->saddr = saddr;
fl4->fl4_dport = dport;
Expand Down Expand Up @@ -128,7 +123,6 @@ struct flowi6 {
#define flowi6_proto __fl_common.flowic_proto
#define flowi6_flags __fl_common.flowic_flags
#define flowi6_secid __fl_common.flowic_secid
#define flowi6_uid __fl_common.flowic_uid
struct in6_addr daddr;
struct in6_addr saddr;
__be32 flowlabel;
Expand Down Expand Up @@ -172,7 +166,6 @@ struct flowi {
#define flowi_proto u.__fl_common.flowic_proto
#define flowi_flags u.__fl_common.flowic_flags
#define flowi_secid u.__fl_common.flowic_secid
#define flowi_uid u.__fl_common.flowic_uid
} __attribute__((__aligned__(BITS_PER_LONG/8)));

static inline struct flowi *flowi4_to_flowi(struct flowi4 *fl4)
Expand Down
1 change: 0 additions & 1 deletion include/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ struct ip_reply_arg {
/* -1 if not needed */
int bound_dev_if;
u8 tos;
kuid_t uid;
};

#define IP_REPLY_ARG_NOSRCCHECK 1
Expand Down
2 changes: 1 addition & 1 deletion include/net/ip6_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extern int rt6_route_rcv(struct net_device *dev,
const struct in6_addr *gwaddr);

extern void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
int oif, u32 mark, kuid_t uid);
int oif, u32 mark);
extern void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk,
__be32 mtu);
extern void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark);
Expand Down
5 changes: 2 additions & 3 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi
flowi4_init_output(fl4, oif, sk ? sk->sk_mark : 0, tos,
RT_SCOPE_UNIVERSE, proto,
sk ? inet_sk_flowi_flags(sk) : 0,
daddr, saddr, dport, sport, sock_i_uid(sk));
daddr, saddr, dport, sport);
if (sk)
security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
return ip_route_output_flow(net, fl4, sk);
Expand Down Expand Up @@ -253,8 +253,7 @@ static inline void ip_route_connect_init(struct flowi4 *fl4, __be32 dst, __be32
flow_flags |= FLOWI_FLAG_CAN_SLEEP;

flowi4_init_output(fl4, oif, sk->sk_mark, tos, RT_SCOPE_UNIVERSE,
protocol, flow_flags, dst, src, dport, sport,
sock_i_uid(sk));
protocol, flow_flags, dst, src, dport, sport);
}

static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
Expand Down
2 changes: 0 additions & 2 deletions include/uapi/linux/fib_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ enum {
FRA_TABLE, /* Extended table id */
FRA_FWMASK, /* mask for netfilter mark */
FRA_OIFNAME,
FRA_UID_START, /* UID range */
FRA_UID_END,
__FRA_MAX
};

Expand Down
1 change: 0 additions & 1 deletion include/uapi/linux/rtnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ enum rtattr_type_t {
RTA_TABLE,
RTA_MARK,
RTA_MFC_STATS,
RTA_UID,
__RTA_MAX
};

Expand Down
53 changes: 2 additions & 51 deletions net/core/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
r->pref = pref;
r->table = table;
r->flags = flags;
r->uid_start = INVALID_UID;
r->uid_end = INVALID_UID;
r->fr_net = hold_net(ops->fro_net);

/* The lock is not required here, the list in unreacheable
Expand Down Expand Up @@ -181,23 +179,6 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
}
EXPORT_SYMBOL_GPL(fib_rules_unregister);

static inline kuid_t fib_nl_uid(struct nlattr *nla)
{
return make_kuid(current_user_ns(), nla_get_u32(nla));
}

static int nla_put_uid(struct sk_buff *skb, int idx, kuid_t uid)
{
return nla_put_u32(skb, idx, from_kuid_munged(current_user_ns(), uid));
}

static int fib_uid_range_match(struct flowi *fl, struct fib_rule *rule)
{
return (!uid_valid(rule->uid_start) && !uid_valid(rule->uid_end)) ||
(uid_gte(fl->flowi_uid, rule->uid_start) &&
uid_lte(fl->flowi_uid, rule->uid_end));
}

static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
struct flowi *fl, int flags)
{
Expand All @@ -212,9 +193,6 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
if ((rule->mark ^ fl->flowi_mark) & rule->mark_mask)
goto out;

if (!fib_uid_range_match(fl, rule))
goto out;

ret = ops->match(rule, fl, flags);
out:
return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
Expand Down Expand Up @@ -385,19 +363,6 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
} else if (rule->action == FR_ACT_GOTO)
goto errout_free;

/* UID start and end must either both be valid or both unspecified. */
rule->uid_start = rule->uid_end = INVALID_UID;
if (tb[FRA_UID_START] || tb[FRA_UID_END]) {
if (tb[FRA_UID_START] && tb[FRA_UID_END]) {
rule->uid_start = fib_nl_uid(tb[FRA_UID_START]);
rule->uid_end = fib_nl_uid(tb[FRA_UID_END]);
}
if (!uid_valid(rule->uid_start) ||
!uid_valid(rule->uid_end) ||
!uid_lte(rule->uid_start, rule->uid_end))
goto errout_free;
}

err = ops->configure(rule, skb, frh, tb);
if (err < 0)
goto errout_free;
Expand Down Expand Up @@ -504,14 +469,6 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh)
(rule->mark_mask != nla_get_u32(tb[FRA_FWMASK])))
continue;

if (tb[FRA_UID_START] &&
!uid_eq(rule->uid_start, fib_nl_uid(tb[FRA_UID_START])))
continue;

if (tb[FRA_UID_END] &&
!uid_eq(rule->uid_end, fib_nl_uid(tb[FRA_UID_END])))
continue;

if (!ops->compare(rule, frh, tb))
continue;

Expand Down Expand Up @@ -568,9 +525,7 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
+ nla_total_size(4) /* FRA_PRIORITY */
+ nla_total_size(4) /* FRA_TABLE */
+ nla_total_size(4) /* FRA_FWMARK */
+ nla_total_size(4) /* FRA_FWMASK */
+ nla_total_size(4) /* FRA_UID_START */
+ nla_total_size(4); /* FRA_UID_END */
+ nla_total_size(4); /* FRA_FWMASK */

if (ops->nlmsg_payload)
payload += ops->nlmsg_payload(rule);
Expand Down Expand Up @@ -624,11 +579,7 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
((rule->mark_mask || rule->mark) &&
nla_put_u32(skb, FRA_FWMASK, rule->mark_mask)) ||
(rule->target &&
nla_put_u32(skb, FRA_GOTO, rule->target)) ||
(uid_valid(rule->uid_start) &&
nla_put_uid(skb, FRA_UID_START, rule->uid_start)) ||
(uid_valid(rule->uid_end) &&
nla_put_uid(skb, FRA_UID_END, rule->uid_end)))
nla_put_u32(skb, FRA_GOTO, rule->target)))
goto nla_put_failure;
if (ops->fill(rule, skb, frh) < 0)
goto nla_put_failure;
Expand Down
1 change: 0 additions & 1 deletion net/ipv4/fib_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
[RTA_METRICS] = { .type = NLA_NESTED },
[RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
[RTA_FLOW] = { .type = NLA_U32 },
[RTA_UID] = { .type = NLA_U32 },
};

static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
Expand Down
6 changes: 2 additions & 4 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ struct dst_entry *inet_csk_route_req(struct sock *sk,
sk->sk_protocol,
flags,
(opt && opt->opt.srr) ? opt->opt.faddr : ireq->rmt_addr,
ireq->loc_addr, ireq->rmt_port, inet_sk(sk)->inet_sport,
sock_i_uid(sk));
ireq->loc_addr, ireq->rmt_port, inet_sk(sk)->inet_sport);
security_req_classify_flow(req, flowi4_to_flowi(fl4));
rt = ip_route_output_flow(net, fl4, sk);
if (IS_ERR(rt))
Expand Down Expand Up @@ -459,8 +458,7 @@ struct dst_entry *inet_csk_route_child_sock(struct sock *sk,
RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE,
sk->sk_protocol, inet_sk_flowi_flags(sk),
(opt && opt->opt.srr) ? opt->opt.faddr : ireq->rmt_addr,
ireq->loc_addr, ireq->rmt_port, inet_sk(sk)->inet_sport,
sock_i_uid(sk));
ireq->loc_addr, ireq->rmt_port, inet_sk(sk)->inet_sport);
security_req_classify_flow(req, flowi4_to_flowi(fl4));
rt = ip_route_output_flow(net, fl4, sk);
if (IS_ERR(rt))
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,7 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, __be32 daddr,
RT_SCOPE_UNIVERSE, ip_hdr(skb)->protocol,
ip_reply_arg_flowi_flags(arg),
daddr, saddr,
tcp_hdr(skb)->source, tcp_hdr(skb)->dest,
arg->uid);
tcp_hdr(skb)->source, tcp_hdr(skb)->dest);
security_skb_classify_flow(skb, flowi4_to_flowi(&fl4));
rt = ip_route_output_key(net, &fl4);
if (IS_ERR(rt))
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,

flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos,
RT_SCOPE_UNIVERSE, sk->sk_protocol,
inet_sk_flowi_flags(sk), faddr, saddr, 0, 0,
sock_i_uid(sk));
inet_sk_flowi_flags(sk), faddr, saddr, 0, 0);

security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
rt = ip_route_output_flow(net, &fl4, sk);
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
RT_SCOPE_UNIVERSE,
inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol,
inet_sk_flowi_flags(sk) | FLOWI_FLAG_CAN_SLEEP,
daddr, saddr, 0, 0,
sock_i_uid(sk));
daddr, saddr, 0, 0);

if (!inet->hdrincl) {
err = raw_probe_proto_opt(&fl4, msg);
Expand Down
25 changes: 6 additions & 19 deletions net/ipv4/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
}
EXPORT_SYMBOL(__ip_select_ident);

static void __build_flow_key(struct flowi4 *fl4, struct sock *sk,
static void __build_flow_key(struct flowi4 *fl4, const struct sock *sk,
const struct iphdr *iph,
int oif, u8 tos,
u8 prot, u32 mark, int flow_flags)
Expand All @@ -516,12 +516,11 @@ static void __build_flow_key(struct flowi4 *fl4, struct sock *sk,
flowi4_init_output(fl4, oif, mark, tos,
RT_SCOPE_UNIVERSE, prot,
flow_flags,
iph->daddr, iph->saddr, 0, 0,
sock_i_uid(sk));
iph->daddr, iph->saddr, 0, 0);
}

static void build_skb_flow_key(struct flowi4 *fl4, const struct sk_buff *skb,
struct sock *sk)
const struct sock *sk)
{
const struct iphdr *iph = ip_hdr(skb);
int oif = skb->dev->ifindex;
Expand All @@ -532,7 +531,7 @@ static void build_skb_flow_key(struct flowi4 *fl4, const struct sk_buff *skb,
__build_flow_key(fl4, sk, iph, oif, tos, prot, mark, 0);
}

static void build_sk_flow_key(struct flowi4 *fl4, struct sock *sk)
static void build_sk_flow_key(struct flowi4 *fl4, const struct sock *sk)
{
const struct inet_sock *inet = inet_sk(sk);
const struct ip_options_rcu *inet_opt;
Expand All @@ -546,12 +545,11 @@ static void build_sk_flow_key(struct flowi4 *fl4, struct sock *sk)
RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE,
inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol,
inet_sk_flowi_flags(sk),
daddr, inet->inet_saddr, 0, 0,
sock_i_uid(sk));
daddr, inet->inet_saddr, 0, 0);
rcu_read_unlock();
}

static void ip_rt_build_flow_key(struct flowi4 *fl4, struct sock *sk,
static void ip_rt_build_flow_key(struct flowi4 *fl4, const struct sock *sk,
const struct sk_buff *skb)
{
if (skb)
Expand Down Expand Up @@ -2290,11 +2288,6 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
nla_put_u32(skb, RTA_MARK, fl4->flowi4_mark))
goto nla_put_failure;

if (!uid_eq(fl4->flowi4_uid, INVALID_UID) &&
nla_put_u32(skb, RTA_UID,
from_kuid_munged(current_user_ns(), fl4->flowi4_uid)))
goto nla_put_failure;

error = rt->dst.error;

if (rt_is_input_route(rt)) {
Expand Down Expand Up @@ -2344,7 +2337,6 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
int err;
int mark;
struct sk_buff *skb;
kuid_t uid;

err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv4_policy);
if (err < 0)
Expand Down Expand Up @@ -2372,18 +2364,13 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
dst = tb[RTA_DST] ? nla_get_be32(tb[RTA_DST]) : 0;
iif = tb[RTA_IIF] ? nla_get_u32(tb[RTA_IIF]) : 0;
mark = tb[RTA_MARK] ? nla_get_u32(tb[RTA_MARK]) : 0;
if (tb[RTA_UID])
uid = make_kuid(current_user_ns(), nla_get_u32(tb[RTA_UID]));
else
uid = (iif ? INVALID_UID : current_uid());

memset(&fl4, 0, sizeof(fl4));
fl4.daddr = dst;
fl4.saddr = src;
fl4.flowi4_tos = rtm->rtm_tos;
fl4.flowi4_oif = tb[RTA_OIF] ? nla_get_u32(tb[RTA_OIF]) : 0;
fl4.flowi4_mark = mark;
fl4.flowi4_uid = uid;

if (iif) {
struct net_device *dev;
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/syncookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE, IPPROTO_TCP,
inet_sk_flowi_flags(sk),
(opt && opt->srr) ? opt->faddr : ireq->rmt_addr,
ireq->loc_addr, th->source, th->dest,
sock_i_uid(sk));
ireq->loc_addr, th->source, th->dest);
security_req_classify_flow(req, flowi4_to_flowi(&fl4));
rt = ip_route_output_key(sock_net(sk), &fl4);
if (IS_ERR(rt)) {
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
flowi4_init_output(fl4, ipc.oif, sk->sk_mark, tos,
RT_SCOPE_UNIVERSE, sk->sk_protocol,
inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
faddr, saddr, dport, inet->inet_sport,
sock_i_uid(sk));
faddr, saddr, dport, inet->inet_sport);

security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
rt = ip_route_output_flow(net, fl4, sk);
Expand Down
Loading

0 comments on commit a11e5dc

Please sign in to comment.