Skip to content

Commit a7cb5a4

Browse files
committed
userns: Print out socket uids in a user namespace aware fashion.
Cc: Alexey Kuznetsov <[email protected]> Cc: James Morris <[email protected]> Cc: Hideaki YOSHIFUJI <[email protected]> Cc: Patrick McHardy <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Sridhar Samudrala <[email protected]> Acked-by: Vlad Yasevich <[email protected]> Acked-by: David S. Miller <[email protected]> Acked-by: Serge Hallyn <[email protected]> Signed-off-by: Eric W. Biederman <[email protected]>
1 parent adb37c4 commit a7cb5a4

File tree

16 files changed

+36
-27
lines changed

16 files changed

+36
-27
lines changed

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,8 @@ struct tcp_iter_state {
15091509
sa_family_t family;
15101510
enum tcp_seq_states state;
15111511
struct sock *syn_wait_sk;
1512-
int bucket, offset, sbucket, num, uid;
1512+
int bucket, offset, sbucket, num;
1513+
kuid_t uid;
15131514
loff_t last_pos;
15141515
};
15151516

init/Kconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,25 +942,19 @@ config UIDGID_CONVERTED
942942
depends on PROC_EVENTS = n
943943

944944
# Networking
945-
depends on PACKET = n
946945
depends on NET_9P = n
947-
depends on IPX = n
948-
depends on PHONET = n
949946
depends on NET_CLS_FLOW = n
950947
depends on NETFILTER_XT_MATCH_OWNER = n
951948
depends on NETFILTER_XT_MATCH_RECENT = n
952949
depends on NETFILTER_XT_TARGET_LOG = n
953950
depends on NETFILTER_NETLINK_LOG = n
954951
depends on INET = n
955952
depends on IPV6 = n
956-
depends on IP_SCTP = n
957953
depends on AF_RXRPC = n
958-
depends on LLC2 = n
959954
depends on NET_KEY = n
960955
depends on INET_DIAG = n
961956
depends on DNS_RESOLVER = n
962957
depends on AX25 = n
963-
depends on ATALK = n
964958

965959
# Filesystems
966960
depends on USB_GADGETFS = n

net/appletalk/atalk_proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ static int atalk_seq_socket_show(struct seq_file *seq, void *v)
183183
ntohs(at->dest_net), at->dest_node, at->dest_port,
184184
sk_wmem_alloc_get(s),
185185
sk_rmem_alloc_get(s),
186-
s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
186+
s->sk_state,
187+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(s)));
187188
out:
188189
return 0;
189190
}

net/ipv4/ping.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,9 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
845845
bucket, src, srcp, dest, destp, sp->sk_state,
846846
sk_wmem_alloc_get(sp),
847847
sk_rmem_alloc_get(sp),
848-
0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
848+
0, 0L, 0,
849+
from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
850+
0, sock_i_ino(sp),
849851
atomic_read(&sp->sk_refcnt), sp,
850852
atomic_read(&sp->sk_drops), len);
851853
}

net/ipv4/raw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,9 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
992992
i, src, srcp, dest, destp, sp->sk_state,
993993
sk_wmem_alloc_get(sp),
994994
sk_rmem_alloc_get(sp),
995-
0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
995+
0, 0L, 0,
996+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
997+
0, sock_i_ino(sp),
996998
atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
997999
}
9981000

net/ipv4/tcp_ipv4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo)
23822382
EXPORT_SYMBOL(tcp_proc_unregister);
23832383

23842384
static void get_openreq4(const struct sock *sk, const struct request_sock *req,
2385-
struct seq_file *f, int i, int uid, int *len)
2385+
struct seq_file *f, int i, kuid_t uid, int *len)
23862386
{
23872387
const struct inet_request_sock *ireq = inet_rsk(req);
23882388
int ttd = req->expires - jiffies;
@@ -2399,7 +2399,7 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
23992399
1, /* timers active (only the expire timer) */
24002400
jiffies_to_clock_t(ttd),
24012401
req->retrans,
2402-
uid,
2402+
from_kuid_munged(seq_user_ns(f), uid),
24032403
0, /* non standard timer */
24042404
0, /* open_requests have no inode */
24052405
atomic_read(&sk->sk_refcnt),
@@ -2450,7 +2450,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
24502450
timer_active,
24512451
jiffies_to_clock_t(timer_expires - jiffies),
24522452
icsk->icsk_retransmits,
2453-
sock_i_uid(sk),
2453+
from_kuid_munged(seq_user_ns(f), sock_i_uid(sk)),
24542454
icsk->icsk_probes_out,
24552455
sock_i_ino(sk),
24562456
atomic_read(&sk->sk_refcnt), sk,

net/ipv4/udp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,9 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
21102110
bucket, src, srcp, dest, destp, sp->sk_state,
21112111
sk_wmem_alloc_get(sp),
21122112
sk_rmem_alloc_get(sp),
2113-
0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
2113+
0, 0L, 0,
2114+
from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
2115+
0, sock_i_ino(sp),
21142116
atomic_read(&sp->sk_refcnt), sp,
21152117
atomic_read(&sp->sk_drops), len);
21162118
}

net/ipv6/raw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
12511251
sk_wmem_alloc_get(sp),
12521252
sk_rmem_alloc_get(sp),
12531253
0, 0L, 0,
1254-
sock_i_uid(sp), 0,
1254+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
1255+
0,
12551256
sock_i_ino(sp),
12561257
atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
12571258
}

net/ipv6/tcp_ipv6.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ static void tcp_v6_destroy_sock(struct sock *sk)
18031803
#ifdef CONFIG_PROC_FS
18041804
/* Proc filesystem TCPv6 sock list dumping. */
18051805
static void get_openreq6(struct seq_file *seq,
1806-
const struct sock *sk, struct request_sock *req, int i, int uid)
1806+
const struct sock *sk, struct request_sock *req, int i, kuid_t uid)
18071807
{
18081808
int ttd = req->expires - jiffies;
18091809
const struct in6_addr *src = &inet6_rsk(req)->loc_addr;
@@ -1827,7 +1827,7 @@ static void get_openreq6(struct seq_file *seq,
18271827
1, /* timers active (only the expire timer) */
18281828
jiffies_to_clock_t(ttd),
18291829
req->retrans,
1830-
uid,
1830+
from_kuid_munged(seq_user_ns(seq), uid),
18311831
0, /* non standard timer */
18321832
0, /* open_requests have no inode */
18331833
0, req);
@@ -1877,7 +1877,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
18771877
timer_active,
18781878
jiffies_to_clock_t(timer_expires - jiffies),
18791879
icsk->icsk_retransmits,
1880-
sock_i_uid(sp),
1880+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
18811881
icsk->icsk_probes_out,
18821882
sock_i_ino(sp),
18831883
atomic_read(&sp->sk_refcnt), sp,

net/ipv6/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,8 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
14581458
sk_wmem_alloc_get(sp),
14591459
sk_rmem_alloc_get(sp),
14601460
0, 0L, 0,
1461-
sock_i_uid(sp), 0,
1461+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
1462+
0,
14621463
sock_i_ino(sp),
14631464
atomic_read(&sp->sk_refcnt), sp,
14641465
atomic_read(&sp->sk_drops));

net/ipx/ipx_proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ static int ipx_seq_socket_show(struct seq_file *seq, void *v)
217217
seq_printf(seq, "%08X %08X %02X %03d\n",
218218
sk_wmem_alloc_get(s),
219219
sk_rmem_alloc_get(s),
220-
s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
220+
s->sk_state,
221+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(s)));
221222
out:
222223
return 0;
223224
}

net/key/af_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,7 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
36613661
atomic_read(&s->sk_refcnt),
36623662
sk_rmem_alloc_get(s),
36633663
sk_wmem_alloc_get(s),
3664-
sock_i_uid(s),
3664+
from_kuid_munged(seq_user_ns(f), sock_i_uid(s)),
36653665
sock_i_ino(s)
36663666
);
36673667
return 0;

net/llc/llc_proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int llc_seq_socket_show(struct seq_file *seq, void *v)
151151
sk_wmem_alloc_get(sk),
152152
sk_rmem_alloc_get(sk) - llc->copied_seq,
153153
sk->sk_state,
154-
sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
154+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
155155
llc->link);
156156
out:
157157
return 0;

net/packet/af_packet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3846,7 +3846,7 @@ static int packet_seq_show(struct seq_file *seq, void *v)
38463846
po->ifindex,
38473847
po->running,
38483848
atomic_read(&s->sk_rmem_alloc),
3849-
sock_i_uid(s),
3849+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(s)),
38503850
sock_i_ino(s));
38513851
}
38523852

net/phonet/socket.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
612612
sk->sk_protocol, pn->sobject, pn->dobject,
613613
pn->resource, sk->sk_state,
614614
sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
615-
sock_i_uid(sk), sock_i_ino(sk),
615+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
616+
sock_i_ino(sk),
616617
atomic_read(&sk->sk_refcnt), sk,
617618
atomic_read(&sk->sk_drops), &len);
618619
}
@@ -796,7 +797,8 @@ static int pn_res_seq_show(struct seq_file *seq, void *v)
796797
struct sock *sk = *psk;
797798

798799
seq_printf(seq, "%02X %5d %lu%n",
799-
(int) (psk - pnres.sk), sock_i_uid(sk),
800+
(int) (psk - pnres.sk),
801+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
800802
sock_i_ino(sk), &len);
801803
}
802804
seq_printf(seq, "%*s\n", 63 - len, "");

net/sctp/proc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
216216
seq_printf(seq, "%8pK %8pK %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
217217
sctp_sk(sk)->type, sk->sk_state, hash,
218218
epb->bind_addr.port,
219-
sock_i_uid(sk), sock_i_ino(sk));
219+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
220+
sock_i_ino(sk));
220221

221222
sctp_seq_dump_local_addrs(seq, epb);
222223
seq_printf(seq, "\n");
@@ -324,7 +325,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
324325
assoc->assoc_id,
325326
assoc->sndbuf_used,
326327
atomic_read(&assoc->rmem_alloc),
327-
sock_i_uid(sk), sock_i_ino(sk),
328+
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
329+
sock_i_ino(sk),
328330
epb->bind_addr.port,
329331
assoc->peer.port);
330332
seq_printf(seq, " ");

0 commit comments

Comments
 (0)