Skip to content

Commit 68ada13

Browse files
matttbeintel-lab-lkp
authored andcommitted
tcp: ulp: diag: more info without CAP_NET_ADMIN
When introduced in commit 61723b3 ("tcp: ulp: add functions to dump ulp-specific information"), the whole ULP diag info has been exported only if the requester had CAP_NET_ADMIN. It looks like not everything is sensitive, and some info can be exported to all users in order to ease the debugging from the userspace side without requiring additional capabilities. Each layer should then decide what can be exposed to everybody. The 'net_admin' boolean is then passed to the different layers. On kTLS side, it looks like there is nothing sensitive there, only some metadata about the configuration, no cryptographic information. Then, everything can be exported to all users. On MPTCP side, that's different. The MPTCP-related sequence numbers per subflow should certainly not be exposed to everybody. For example, the DSS mapping and ssn_offset would give all users on the system access to narrow ranges of values for the subflow TCP sequence numbers and MPTCP-level DSNs, and then ease packet injection. The TCP diag interface doesn't expose the TCP sequence numbers for TCP sockets, so best to do the same here. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 447f3ad commit 68ada13

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

include/net/tcp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2598,8 +2598,8 @@ struct tcp_ulp_ops {
25982598
/* cleanup ulp */
25992599
void (*release)(struct sock *sk);
26002600
/* diagnostic */
2601-
int (*get_info)(struct sock *sk, struct sk_buff *skb);
2602-
size_t (*get_info_size)(const struct sock *sk);
2601+
int (*get_info)(struct sock *sk, struct sk_buff *skb, bool net_admin);
2602+
size_t (*get_info_size)(const struct sock *sk, bool net_admin);
26032603
/* clone ulp */
26042604
void (*clone)(const struct request_sock *req, struct sock *newsk,
26052605
const gfp_t priority);

net/ipv4/tcp_diag.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ static int tcp_diag_put_ulp(struct sk_buff *skb, struct sock *sk,
9696
if (err)
9797
goto nla_failure;
9898

99-
if (net_admin && ulp_ops->get_info)
100-
err = ulp_ops->get_info(sk, skb);
99+
if (ulp_ops->get_info)
100+
err = ulp_ops->get_info(sk, skb, net_admin);
101101
if (err)
102102
goto nla_failure;
103103

@@ -170,8 +170,8 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin)
170170
if (ulp_ops) {
171171
size += nla_total_size(0) +
172172
nla_total_size(TCP_ULP_NAME_MAX);
173-
if (net_admin && ulp_ops->get_info_size)
174-
size += ulp_ops->get_info_size(sk);
173+
if (ulp_ops->get_info_size)
174+
size += ulp_ops->get_info_size(sk, net_admin);
175175
}
176176
}
177177
return size;

net/mptcp/diag.c

+26-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <net/netlink.h>
1313
#include "protocol.h"
1414

15-
static int subflow_get_info(struct sock *sk, struct sk_buff *skb)
15+
static int subflow_get_info(struct sock *sk, struct sk_buff *skb, bool net_admin)
1616
{
1717
struct mptcp_subflow_context *sf;
1818
struct nlattr *start;
@@ -56,22 +56,28 @@ static int subflow_get_info(struct sock *sk, struct sk_buff *skb)
5656

5757
if (nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_TOKEN_REM, sf->remote_token) ||
5858
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_TOKEN_LOC, sf->token) ||
59-
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
60-
sf->rel_write_seq) ||
61-
nla_put_u64_64bit(skb, MPTCP_SUBFLOW_ATTR_MAP_SEQ, sf->map_seq,
62-
MPTCP_SUBFLOW_ATTR_PAD) ||
63-
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
64-
sf->map_subflow_seq) ||
65-
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_SSN_OFFSET, sf->ssn_offset) ||
66-
nla_put_u16(skb, MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
67-
sf->map_data_len) ||
6859
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_FLAGS, flags) ||
6960
nla_put_u8(skb, MPTCP_SUBFLOW_ATTR_ID_REM, sf->remote_id) ||
7061
nla_put_u8(skb, MPTCP_SUBFLOW_ATTR_ID_LOC, subflow_get_local_id(sf))) {
7162
err = -EMSGSIZE;
7263
goto nla_failure;
7364
}
7465

66+
/* Only export seq related counters to user with CAP_NET_ADMIN */
67+
if (net_admin &&
68+
(nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
69+
sf->rel_write_seq) ||
70+
nla_put_u64_64bit(skb, MPTCP_SUBFLOW_ATTR_MAP_SEQ, sf->map_seq,
71+
MPTCP_SUBFLOW_ATTR_PAD) ||
72+
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
73+
sf->map_subflow_seq) ||
74+
nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_SSN_OFFSET, sf->ssn_offset) ||
75+
nla_put_u16(skb, MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
76+
sf->map_data_len))) {
77+
err = -EMSGSIZE;
78+
goto nla_failure;
79+
}
80+
7581
rcu_read_unlock();
7682
unlock_sock_fast(sk, slow);
7783
nla_nest_end(skb, start);
@@ -84,22 +90,26 @@ static int subflow_get_info(struct sock *sk, struct sk_buff *skb)
8490
return err;
8591
}
8692

87-
static size_t subflow_get_info_size(const struct sock *sk)
93+
static size_t subflow_get_info_size(const struct sock *sk, bool net_admin)
8894
{
8995
size_t size = 0;
9096

9197
size += nla_total_size(0) + /* INET_ULP_INFO_MPTCP */
9298
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_TOKEN_REM */
9399
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_TOKEN_LOC */
94-
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ */
95-
nla_total_size_64bit(8) + /* MPTCP_SUBFLOW_ATTR_MAP_SEQ */
96-
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_MAP_SFSEQ */
97-
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_SSN_OFFSET */
98-
nla_total_size(2) + /* MPTCP_SUBFLOW_ATTR_MAP_DATALEN */
99100
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_FLAGS */
100101
nla_total_size(1) + /* MPTCP_SUBFLOW_ATTR_ID_REM */
101102
nla_total_size(1) + /* MPTCP_SUBFLOW_ATTR_ID_LOC */
102103
0;
104+
105+
if (net_admin)
106+
size += nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ */
107+
nla_total_size_64bit(8) + /* MPTCP_SUBFLOW_ATTR_MAP_SEQ */
108+
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_MAP_SFSEQ */
109+
nla_total_size(4) + /* MPTCP_SUBFLOW_ATTR_SSN_OFFSET */
110+
nla_total_size(2) + /* MPTCP_SUBFLOW_ATTR_MAP_DATALEN */
111+
0;
112+
103113
return size;
104114
}
105115

net/tls/tls_main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ static u16 tls_user_config(struct tls_context *ctx, bool tx)
10571057
return 0;
10581058
}
10591059

1060-
static int tls_get_info(struct sock *sk, struct sk_buff *skb)
1060+
static int tls_get_info(struct sock *sk, struct sk_buff *skb, bool net_admin)
10611061
{
10621062
u16 version, cipher_type;
10631063
struct tls_context *ctx;
@@ -1115,7 +1115,7 @@ static int tls_get_info(struct sock *sk, struct sk_buff *skb)
11151115
return err;
11161116
}
11171117

1118-
static size_t tls_get_info_size(const struct sock *sk)
1118+
static size_t tls_get_info_size(const struct sock *sk, bool net_admin)
11191119
{
11201120
size_t size = 0;
11211121

0 commit comments

Comments
 (0)