]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: Properly typecast int values to set sk_max_pacing_rate
authorKe Li <keli@akamai.com>
Thu, 22 Oct 2020 06:41:46 +0000 (02:41 -0400)
committerJakub Kicinski <kuba@kernel.org>
Thu, 22 Oct 2020 19:18:25 +0000 (12:18 -0700)
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: 76a9ebe811fb ("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>
net/core/filter.c
net/core/sock.c

index 6d0fa65a4a465d8415a997f18bf0a4defcc68840..2ca5eecebacfa7ffa142245d47b77699238e7132 100644 (file)
@@ -4733,7 +4733,8 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
                                cmpxchg(&sk->sk_pacing_status,
                                        SK_PACING_NONE,
                                        SK_PACING_NEEDED);
-                       sk->sk_max_pacing_rate = (val == ~0U) ? ~0UL : val;
+                       sk->sk_max_pacing_rate = (val == ~0U) ?
+                                                ~0UL : (unsigned int)val;
                        sk->sk_pacing_rate = min(sk->sk_pacing_rate,
                                                 sk->sk_max_pacing_rate);
                        break;
index 4e8729357122156560f716cc6b89b4b7265f3fa0..727ea1cc633ca50fdf423c5ddb985c0ae65f71cf 100644 (file)
@@ -1163,7 +1163,7 @@ set_sndbuf:
 
        case SO_MAX_PACING_RATE:
                {
-               unsigned long ulval = (val == ~0U) ? ~0UL : val;
+               unsigned long ulval = (val == ~0U) ? ~0UL : (unsigned int)val;
 
                if (sizeof(ulval) != sizeof(val) &&
                    optlen >= sizeof(ulval) &&