Skip to content

Commit 4d54cc3

Browse files
Florian Westphaldavem330
authored andcommitted
mptcp: avoid lock_fast usage in accept path
Once event support is added this may need to allocate memory while msk lock is held with softirqs disabled. Not using lock_fast also allows to do the allocation with GFP_KERNEL. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6c714f1 commit 4d54cc3

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

include/net/genetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
struct genl_multicast_group {
1616
char name[GENL_NAMSIZ];
17+
u8 flags;
1718
};
1819

1920
struct genl_ops;

net/mptcp/protocol.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,9 +3260,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
32603260
struct mptcp_sock *msk = mptcp_sk(newsock->sk);
32613261
struct mptcp_subflow_context *subflow;
32623262
struct sock *newsk = newsock->sk;
3263-
bool slowpath;
32643263

3265-
slowpath = lock_sock_fast(newsk);
3264+
lock_sock(newsk);
32663265

32673266
/* PM/worker can now acquire the first subflow socket
32683267
* lock without racing with listener queue cleanup,
@@ -3288,7 +3287,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
32883287
if (!ssk->sk_socket)
32893288
mptcp_sock_graft(ssk, newsock);
32903289
}
3291-
unlock_sock_fast(newsk, slowpath);
3290+
release_sock(newsk);
32923291
}
32933292

32943293
if (inet_csk_listen_poll(ssock->sk))

net/netlink/genetlink.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,43 @@ static struct genl_family genl_ctrl __ro_after_init = {
13601360
.netnsok = true,
13611361
};
13621362

1363+
static int genl_bind(struct net *net, int group)
1364+
{
1365+
const struct genl_family *family;
1366+
unsigned int id;
1367+
int ret = 0;
1368+
1369+
genl_lock_all();
1370+
1371+
idr_for_each_entry(&genl_fam_idr, family, id) {
1372+
const struct genl_multicast_group *grp;
1373+
int i;
1374+
1375+
if (family->n_mcgrps == 0)
1376+
continue;
1377+
1378+
i = group - family->mcgrp_offset;
1379+
if (i < 0 || i >= family->n_mcgrps)
1380+
continue;
1381+
1382+
grp = &family->mcgrps[i];
1383+
if ((grp->flags & GENL_UNS_ADMIN_PERM) &&
1384+
!ns_capable(net->user_ns, CAP_NET_ADMIN))
1385+
ret = -EPERM;
1386+
1387+
break;
1388+
}
1389+
1390+
genl_unlock_all();
1391+
return ret;
1392+
}
1393+
13631394
static int __net_init genl_pernet_init(struct net *net)
13641395
{
13651396
struct netlink_kernel_cfg cfg = {
13661397
.input = genl_rcv,
13671398
.flags = NL_CFG_F_NONROOT_RECV,
1399+
.bind = genl_bind,
13681400
};
13691401

13701402
/* we'll bump the group number right afterwards */

0 commit comments

Comments
 (0)