Skip to content

Commit 700465f

Browse files
okisme25kuba-moo
authored andcommitted
net: Properly typecast int values to set sk_max_pacing_rate
In setsockopt(SO_MAX_PACING_RATE) on 64bit systems, sk_max_pacing_rate, after extended from 'u32' to 'unsigned long', takes unintentionally hiked value whenever assigned from an 'int' value with MSB=1, due to binary sign extension in promoting s32 to u64, e.g. 0x80000000 becomes 0xFFFFFFFF80000000. Thus inflated sk_max_pacing_rate causes subsequent getsockopt to return ~0U unexpectedly. It may also result in increased pacing rate. Fix by explicitly casting the 'int' value to 'unsigned int' before assigning it to sk_max_pacing_rate, for zero extension to happen. Fixes: 76a9ebe ("net: extend sk_pacing_rate to unsigned long") Signed-off-by: Ji Li <jli@akamai.com> Signed-off-by: Ke Li <keli@akamai.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20201022064146.79873-1-keli@akamai.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 594850c commit 700465f

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4733,7 +4733,8 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
47334733
cmpxchg(&sk->sk_pacing_status,
47344734
SK_PACING_NONE,
47354735
SK_PACING_NEEDED);
4736-
sk->sk_max_pacing_rate = (val == ~0U) ? ~0UL : val;
4736+
sk->sk_max_pacing_rate = (val == ~0U) ?
4737+
~0UL : (unsigned int)val;
47374738
sk->sk_pacing_rate = min(sk->sk_pacing_rate,
47384739
sk->sk_max_pacing_rate);
47394740
break;

net/core/sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
11631163

11641164
case SO_MAX_PACING_RATE:
11651165
{
1166-
unsigned long ulval = (val == ~0U) ? ~0UL : val;
1166+
unsigned long ulval = (val == ~0U) ? ~0UL : (unsigned int)val;
11671167

11681168
if (sizeof(ulval) != sizeof(val) &&
11691169
optlen >= sizeof(ulval) &&

0 commit comments

Comments
 (0)