Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup patch to add LXC support #1

Open
wants to merge 1 commit into
base: ElementalX-1.00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,278 changes: 4,278 additions & 0 deletions arch/arm64/configs/elementa-LXC_defconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,15 @@ static int oom_adjust_permission(struct inode *inode, int mask)

p = get_proc_task(inode);
if(p) {
uid = task_uid(p);
uid = __kuid_val(task_uid(p));
put_task_struct(p);
}

/*
* System Server (uid == 1000) is granted access to oom_adj of all
* android applications (uid > 10000) as and services (uid >= 1000)
*/
if (p && (current_fsuid() == 1000) && (uid >= 1000)) {
if (p && (__kuid_val(current_fsuid()) == 1000) && (uid >= 1000)) {
if (inode->i_mode >> 6 & mask) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion 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, sk ? sock_i_uid(sk) : 0);
daddr, saddr, dport, sport, sk ? sock_i_uid(sk) : KUIDT_INIT(0));
if (sk)
security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
return ip_route_output_flow(net, fl4, sk);
Expand Down
3 changes: 2 additions & 1 deletion kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7815,7 +7815,8 @@ cpu_cgroup_allow_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
tcred = __task_cred(task);

if ((current != task) && !capable(CAP_SYS_NICE) &&
cred->euid != tcred->uid && cred->euid != tcred->suid)
// cred->euid != tcred->uid && cred->euid != tcred->suid)
!uid_eq(cred->euid, tcred->uid) && !uid_eq(cred->euid, tcred->suid))
return -EACCES;
}

Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

static inline int current_has_network(void)
{
return in_egroup_p(AID_INET) || capable(CAP_NET_RAW);
return in_egroup_p(KGIDT_INIT(AID_INET)) || capable(CAP_NET_RAW);
}
#else
static inline int current_has_network(void)
Expand Down Expand Up @@ -1879,4 +1879,3 @@ static int __init ipv4_proc_init(void)
#endif /* CONFIG_PROC_FS */

MODULE_ALIAS_NETPROTO(PF_INET);

2 changes: 1 addition & 1 deletion net/ipv4/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static void __build_flow_key(struct flowi4 *fl4, struct sock *sk,
RT_SCOPE_UNIVERSE, prot,
flow_flags,
iph->daddr, iph->saddr, 0, 0,
sk ? sock_i_uid(sk) : 0);
sk ? sock_i_uid(sk) : KUIDT_INIT(0));
}

static void build_skb_flow_key(struct flowi4 *fl4, const struct sk_buff *skb,
Expand Down
8 changes: 4 additions & 4 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
release_sock(sk);

if (copied + copied_syn)
uid_stat_tcp_snd(current_uid(), copied + copied_syn);
uid_stat_tcp_snd(__kuid_val(current_uid()), copied + copied_syn);
return copied + copied_syn;

do_fault:
Expand Down Expand Up @@ -1550,7 +1550,7 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
if (copied > 0) {
tcp_recv_skb(sk, seq, &offset);
tcp_cleanup_rbuf(sk, copied);
uid_stat_tcp_rcv(current_uid(), copied);
uid_stat_tcp_rcv(__kuid_val(current_uid()), copied);
}
return copied;
}
Expand Down Expand Up @@ -1957,7 +1957,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
release_sock(sk);

if (copied > 0)
uid_stat_tcp_rcv(current_uid(), copied);
uid_stat_tcp_rcv(__kuid_val(current_uid()), copied);
return copied;

out:
Expand All @@ -1967,7 +1967,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
recv_urg:
err = tcp_recv_urg(sk, msg, len, flags);
if (err > 0)
uid_stat_tcp_rcv(current_uid(), err);
uid_stat_tcp_rcv(__kuid_val(current_uid()), err);
goto out;

recv_sndq:
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/af_inet6.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

static inline int current_has_network(void)
{
return in_egroup_p(AID_INET) || capable(CAP_NET_RAW);
return in_egroup_p(KGIDT_INIT(AID_INET)) || capable(CAP_NET_RAW);
}
#else
static inline int current_has_network(void)
Expand Down
62 changes: 31 additions & 31 deletions net/netfilter/xt_qtaguid.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,22 @@ static bool can_manipulate_uids(void)
{
/* root pwnd */
return in_egroup_p(xt_qtaguid_ctrl_file->gid)
|| unlikely(!current_fsuid()) || unlikely(!proc_ctrl_write_limited)
|| unlikely(current_fsuid() == xt_qtaguid_ctrl_file->uid);
|| unlikely(!__kuid_val(current_fsuid())) || unlikely(!proc_ctrl_write_limited)
|| unlikely(uid_eq(current_fsuid(), xt_qtaguid_ctrl_file->uid));
}

static bool can_impersonate_uid(uid_t uid)
{
return uid == current_fsuid() || can_manipulate_uids();
return uid == __kuid_val(current_fsuid()) || can_manipulate_uids();
}

static bool can_read_other_uid_stats(uid_t uid)
{
/* root pwnd */
return in_egroup_p(xt_qtaguid_stats_file->gid)
|| unlikely(!current_fsuid()) || uid == current_fsuid()
|| unlikely(!__kuid_val(current_fsuid())) || uid == __kuid_val(current_fsuid())
|| unlikely(!proc_stats_readall_limited)
|| unlikely(current_fsuid() == xt_qtaguid_ctrl_file->uid);
|| unlikely(uid_eq(current_fsuid(), xt_qtaguid_ctrl_file->uid));
}

static inline void dc_add_byte_packets(struct data_counters *counters, int set,
Expand Down Expand Up @@ -542,7 +542,7 @@ static void put_utd_entry(struct uid_tag_data *utd_entry)
"erase utd_entry=%p uid=%u "
"by pid=%u tgid=%u uid=%u\n", __func__,
utd_entry, utd_entry->uid,
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));
BUG_ON(utd_entry->num_active_tags);
rb_erase(&utd_entry->node, &uid_tag_data_tree);
kfree(utd_entry);
Expand Down Expand Up @@ -744,7 +744,7 @@ static int iface_stat_fmt_proc_show(struct seq_file *m, void *v)


CT_DEBUG("qtaguid:proc iface_stat_fmt pid=%u tgid=%u uid=%u\n",
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));

iface_entry = list_entry(v, struct iface_stat, list);

Expand Down Expand Up @@ -1720,7 +1720,7 @@ static bool qtaguid_mt(const struct sk_buff *skb, struct xt_action_param *par)
sk->sk_socket ? sk->sk_socket->file : (void *)-1LL);
filp = sk->sk_socket ? sk->sk_socket->file : NULL;
MT_DEBUG("qtaguid[%d]: filp...uid=%u\n",
par->hooknum, filp ? filp->f_cred->fsuid : -1);
par->hooknum, filp ? filp->f_cred->fsuid : KUIDT_INIT(-1));
}

if (sk == NULL || sk->sk_socket == NULL) {
Expand Down Expand Up @@ -1755,7 +1755,7 @@ static bool qtaguid_mt(const struct sk_buff *skb, struct xt_action_param *par)
atomic64_inc(&qtu_events.match_no_sk_file);
goto put_sock_ret_res;
}
sock_uid = filp->f_cred->fsuid;
sock_uid = __kuid_val(filp->f_cred->fsuid);
/*
* TODO: unhack how to force just accounting.
* For now we only do iface stats when the uid-owner is not requested
Expand All @@ -1770,17 +1770,17 @@ static bool qtaguid_mt(const struct sk_buff *skb, struct xt_action_param *par)
* Thus (!a && b) || (a && !b) == a ^ b
*/
if (info->match & XT_QTAGUID_UID)
if ((filp->f_cred->fsuid >= info->uid_min &&
filp->f_cred->fsuid <= info->uid_max) ^
if ((__kuid_val(filp->f_cred->fsuid) >= info->uid_min &&
__kuid_val(filp->f_cred->fsuid) <= info->uid_max) ^
!(info->invert & XT_QTAGUID_UID)) {
MT_DEBUG("qtaguid[%d]: leaving uid not matching\n",
par->hooknum);
res = false;
goto put_sock_ret_res;
}
if (info->match & XT_QTAGUID_GID)
if ((filp->f_cred->fsgid >= info->gid_min &&
filp->f_cred->fsgid <= info->gid_max) ^
if ((__kgid_val(filp->f_cred->fsgid) >= info->gid_min &&
__kgid_val(filp->f_cred->fsgid) <= info->gid_max) ^
!(info->invert & XT_QTAGUID_GID)) {
MT_DEBUG("qtaguid[%d]: leaving gid not matching\n",
par->hooknum);
Expand Down Expand Up @@ -1919,7 +1919,7 @@ static int qtaguid_ctrl_proc_show(struct seq_file *m, void *v)
long f_count;

CT_DEBUG("qtaguid: proc ctrl pid=%u tgid=%u uid=%u\n",
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));

if (sock_tag_entry != SEQ_START_TOKEN) {
uid = get_uid_from_tag(sock_tag_entry->tag);
Expand Down Expand Up @@ -2005,11 +2005,11 @@ static int ctrl_cmd_delete(const char *input)
goto err;
}
if (argc < 3) {
uid = current_fsuid();
uid = __kuid_val(current_fsuid());
} else if (!can_impersonate_uid(uid)) {
pr_info("qtaguid: ctrl_delete(%s): "
"insufficient priv from pid=%u tgid=%u uid=%u\n",
input, current->pid, current->tgid, current_fsuid());
input, current->pid, current->tgid, __kuid_val(current_fsuid()));
res = -EPERM;
goto err;
}
Expand Down Expand Up @@ -2160,7 +2160,7 @@ static int ctrl_cmd_counter_set(const char *input)
if (!can_manipulate_uids()) {
pr_info("qtaguid: ctrl_counterset(%s): "
"insufficient priv from pid=%u tgid=%u uid=%u\n",
input, current->pid, current->tgid, current_fsuid());
input, current->pid, current->tgid, __kuid_val(current_fsuid()));
res = -EPERM;
goto err;
}
Expand Down Expand Up @@ -2221,7 +2221,7 @@ static int ctrl_cmd_tag(const char *input)
pr_info("qtaguid: ctrl_tag(%s): failed to lookup"
" sock_fd=%d err=%d pid=%u tgid=%u uid=%u\n",
input, sock_fd, res, current->pid, current->tgid,
current_fsuid());
__kuid_val(current_fsuid()));
goto err;
}
CT_DEBUG("qtaguid: ctrl_tag(%s): socket->...->f_count=%ld ->sk=%p\n",
Expand All @@ -2238,16 +2238,16 @@ static int ctrl_cmd_tag(const char *input)
"pid=%u tgid=%u uid=%u euid=%u fsuid=%u "
"ctrl.gid=%u in_group()=%d in_egroup()=%d\n",
input, current->pid, current->tgid, current_uid(),
current_euid(), current_fsuid(),
current_euid(), __kuid_val(current_fsuid()),
xt_qtaguid_ctrl_file->gid,
in_group_p(xt_qtaguid_ctrl_file->gid),
in_egroup_p(xt_qtaguid_ctrl_file->gid));
if (argc < 4) {
uid = current_fsuid();
uid = __kuid_val(current_fsuid());
} else if (!can_impersonate_uid(uid)) {
pr_info("qtaguid: ctrl_tag(%s): "
"insufficient priv from pid=%u tgid=%u uid=%u\n",
input, current->pid, current->tgid, current_fsuid());
input, current->pid, current->tgid, __kuid_val(current_fsuid()));
res = -EPERM;
goto err_put;
}
Expand Down Expand Up @@ -2314,7 +2314,7 @@ static int ctrl_cmd_tag(const char *input)
"User space forgot to open /dev/xt_qtaguid? "
"pid=%u tgid=%u uid=%u\n", __func__,
current->pid, current->tgid,
current_fsuid());
__kuid_val(current_fsuid()));
else
list_add(&sock_tag_entry->list,
&pqd_entry->sock_tag_list);
Expand Down Expand Up @@ -2369,7 +2369,7 @@ static int ctrl_cmd_untag(const char *input)
pr_info("qtaguid: ctrl_untag(%s): failed to lookup"
" sock_fd=%d err=%d pid=%u tgid=%u uid=%u\n",
input, sock_fd, res, current->pid, current->tgid,
current_fsuid());
__kuid_val(current_fsuid()));
goto err;
}
CT_DEBUG("qtaguid: ctrl_untag(%s): socket->...->f_count=%ld ->sk=%p\n",
Expand Down Expand Up @@ -2403,7 +2403,7 @@ static int ctrl_cmd_untag(const char *input)
pr_warn_once("qtaguid: %s(): "
"User space forgot to open /dev/xt_qtaguid? "
"pid=%u tgid=%u uid=%u\n", __func__,
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));
else
list_del(&sock_tag_entry->list);
spin_unlock_bh(&uid_tag_data_tree_lock);
Expand Down Expand Up @@ -2446,7 +2446,7 @@ static ssize_t qtaguid_ctrl_parse(const char *input, size_t count)
ssize_t res;

CT_DEBUG("qtaguid: ctrl(%s): pid=%u tgid=%u uid=%u\n",
input, current->pid, current->tgid, current_fsuid());
input, current->pid, current->tgid, __kuid_val(current_fsuid()));

cmd = input[0];
/* Collect params for commands */
Expand Down Expand Up @@ -2534,7 +2534,7 @@ static int pp_stats_line(struct seq_file *m, struct tag_stat *ts_entry,
"from pid=%u tgid=%u uid=%u stats.gid=%u\n",
ppi->iface_entry->ifname,
get_atag_from_tag(tag), stat_uid,
current->pid, current->tgid, current_fsuid(),
current->pid, current->tgid, __kuid_val(current_fsuid()),
xt_qtaguid_stats_file->gid);
return 0;
}
Expand Down Expand Up @@ -2737,12 +2737,12 @@ static int qtudev_open(struct inode *inode, struct file *file)
return 0;

DR_DEBUG("qtaguid: qtudev_open(): pid=%u tgid=%u uid=%u\n",
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));

spin_lock_bh(&uid_tag_data_tree_lock);

/* Look for existing uid data, or alloc one. */
utd_entry = get_uid_data(current_fsuid(), &utd_entry_found);
utd_entry = get_uid_data(__kuid_val(current_fsuid()), &utd_entry_found);
if (IS_ERR_OR_NULL(utd_entry)) {
res = PTR_ERR(utd_entry);
goto err_unlock;
Expand All @@ -2754,7 +2754,7 @@ static int qtudev_open(struct inode *inode, struct file *file)
if (pqd_entry) {
pr_err("qtaguid: qtudev_open(): %u/%u %u "
"%s already opened\n",
current->pid, current->tgid, current_fsuid(),
current->pid, current->tgid, __kuid_val(current_fsuid()),
QTU_DEV_NAME);
res = -EBUSY;
goto err_unlock_free_utd;
Expand All @@ -2764,7 +2764,7 @@ static int qtudev_open(struct inode *inode, struct file *file)
if (!new_pqd_entry) {
pr_err("qtaguid: qtudev_open(): %u/%u %u: "
"proc data alloc failed\n",
current->pid, current->tgid, current_fsuid());
current->pid, current->tgid, __kuid_val(current_fsuid()));
res = -ENOMEM;
goto err_unlock_free_utd;
}
Expand All @@ -2778,7 +2778,7 @@ static int qtudev_open(struct inode *inode, struct file *file)

spin_unlock_bh(&uid_tag_data_tree_lock);
DR_DEBUG("qtaguid: tracking data for uid=%u in pqd=%p\n",
current_fsuid(), new_pqd_entry);
__kuid_val(current_fsuid()), new_pqd_entry);
file->private_data = new_pqd_entry;
return 0;

Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/xt_quota2.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
spin_unlock_bh(&counter_list_lock);
goto out;
}
proc_set_user(p, quota_list_uid, quota_list_gid);
proc_set_user(p, make_kuid(&init_user_ns, quota_list_uid), make_kgid(&init_user_ns, quota_list_gid));
return e;

out:
Expand Down
6 changes: 3 additions & 3 deletions security/commoncap.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
struct user_namespace *ns = targ_ns;

#ifdef CONFIG_ANDROID_PARANOID_NETWORK
if (cap == CAP_NET_RAW && in_egroup_p(AID_NET_RAW))
if (cap == CAP_NET_RAW && in_egroup_p(make_kgid(ns, AID_NET_RAW)))
return 0;
if (cap == CAP_NET_ADMIN && in_egroup_p(AID_NET_ADMIN))
if (cap == CAP_NET_ADMIN && in_egroup_p(make_kgid(ns, AID_NET_ADMIN)))
return 0;
#endif

Expand All @@ -102,7 +102,7 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
if (ns == &init_user_ns)
return -EPERM;

/*
/*
* The owner of the user namespace in the parent of the
* user namespace has all caps.
*/
Expand Down