Skip to content

Commit 790709f

Browse files
edumazetdavem330
authored andcommitted
net: relax SO_TXTIME CAP_NET_ADMIN check
Now sch_fq has horizon feature, we want to allow QUIC/UDP applications to use EDT model so that pacing can be offloaded to the kernel (sch_fq) or the NIC. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Willem de Bruijn <willemb@google.com> Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 738fea3 commit 790709f

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎net/core/sock.c‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,23 +1152,31 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
11521152
break;
11531153

11541154
case SO_TXTIME:
1155-
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
1156-
ret = -EPERM;
1157-
} else if (optlen != sizeof(struct sock_txtime)) {
1155+
if (optlen != sizeof(struct sock_txtime)) {
11581156
ret = -EINVAL;
1157+
break;
11591158
} else if (copy_from_user(&sk_txtime, optval,
11601159
sizeof(struct sock_txtime))) {
11611160
ret = -EFAULT;
1161+
break;
11621162
} else if (sk_txtime.flags & ~SOF_TXTIME_FLAGS_MASK) {
11631163
ret = -EINVAL;
1164-
} else {
1165-
sock_valbool_flag(sk, SOCK_TXTIME, true);
1166-
sk->sk_clockid = sk_txtime.clockid;
1167-
sk->sk_txtime_deadline_mode =
1168-
!!(sk_txtime.flags & SOF_TXTIME_DEADLINE_MODE);
1169-
sk->sk_txtime_report_errors =
1170-
!!(sk_txtime.flags & SOF_TXTIME_REPORT_ERRORS);
1164+
break;
1165+
}
1166+
/* CLOCK_MONOTONIC is only used by sch_fq, and this packet
1167+
* scheduler has enough safe guards.
1168+
*/
1169+
if (sk_txtime.clockid != CLOCK_MONOTONIC &&
1170+
!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
1171+
ret = -EPERM;
1172+
break;
11711173
}
1174+
sock_valbool_flag(sk, SOCK_TXTIME, true);
1175+
sk->sk_clockid = sk_txtime.clockid;
1176+
sk->sk_txtime_deadline_mode =
1177+
!!(sk_txtime.flags & SOF_TXTIME_DEADLINE_MODE);
1178+
sk->sk_txtime_report_errors =
1179+
!!(sk_txtime.flags & SOF_TXTIME_REPORT_ERRORS);
11721180
break;
11731181

11741182
case SO_BINDTOIFINDEX:

0 commit comments

Comments
 (0)