Skip to content

Commit a53b72c

Browse files
ebiedermdavem330
authored andcommitted
net: Move the permission check in sock_diag_put_filterinfo to packet_diag_dump
The permission check in sock_diag_put_filterinfo is wrong, and it is so removed from it's sources it is not clear why it is wrong. Move the computation into packet_diag_dump and pass a bool of the result into sock_diag_filterinfo. This does not yet correct the capability check but instead simply moves it to make it clear what is going on. Reported-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5187cd0 commit a53b72c

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎include/linux/sock_diag.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int sock_diag_check_cookie(void *sk, __u32 *cookie);
2323
void sock_diag_save_cookie(void *sk, __u32 *cookie);
2424

2525
int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
26-
int sock_diag_put_filterinfo(struct sock *sk,
26+
int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
2727
struct sk_buff *skb, int attrtype);
2828

2929
#endif

‎net/core/sock_diag.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype)
4949
}
5050
EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
5151

52-
int sock_diag_put_filterinfo(struct sock *sk,
52+
int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
5353
struct sk_buff *skb, int attrtype)
5454
{
5555
struct sock_fprog_kern *fprog;
@@ -58,7 +58,7 @@ int sock_diag_put_filterinfo(struct sock *sk,
5858
unsigned int flen;
5959
int err = 0;
6060

61-
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
61+
if (!may_report_filterinfo) {
6262
nla_reserve(skb, attrtype, 0);
6363
return 0;
6464
}

‎net/packet/diag.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static int pdiag_put_fanout(struct packet_sock *po, struct sk_buff *nlskb)
128128

129129
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
130130
struct packet_diag_req *req,
131+
bool may_report_filterinfo,
131132
struct user_namespace *user_ns,
132133
u32 portid, u32 seq, u32 flags, int sk_ino)
133134
{
@@ -172,7 +173,8 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
172173
goto out_nlmsg_trim;
173174

174175
if ((req->pdiag_show & PACKET_SHOW_FILTER) &&
175-
sock_diag_put_filterinfo(sk, skb, PACKET_DIAG_FILTER))
176+
sock_diag_put_filterinfo(may_report_filterinfo, sk, skb,
177+
PACKET_DIAG_FILTER))
176178
goto out_nlmsg_trim;
177179

178180
return nlmsg_end(skb, nlh);
@@ -188,9 +190,11 @@ static int packet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
188190
struct packet_diag_req *req;
189191
struct net *net;
190192
struct sock *sk;
193+
bool may_report_filterinfo;
191194

192195
net = sock_net(skb->sk);
193196
req = nlmsg_data(cb->nlh);
197+
may_report_filterinfo = ns_capable(net->user_ns, CAP_NET_ADMIN);
194198

195199
mutex_lock(&net->packet.sklist_lock);
196200
sk_for_each(sk, &net->packet.sklist) {
@@ -200,6 +204,7 @@ static int packet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
200204
goto next;
201205

202206
if (sk_diag_fill(sk, skb, req,
207+
may_report_filterinfo,
203208
sk_user_ns(NETLINK_CB(cb->skb).sk),
204209
NETLINK_CB(cb->skb).portid,
205210
cb->nlh->nlmsg_seq, NLM_F_MULTI,

0 commit comments

Comments
 (0)