From patchwork Tue Oct 27 13:44:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 312609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB192C55179 for ; Tue, 27 Oct 2020 15:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8453522282 for ; Tue, 27 Oct 2020 15:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812519; bh=QElG1aAp5okCuT19usec8CSs9Gw/L67dK4qjvYH3PIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=a3u4pDNljjPkUlguafq93bkR0jfkLs3VyxRbIA2t8o2OkJrXT05yEsZ8M2zgVXT/N jXKXW7zBdmYYjG4ogrfOwC138DRuA/G8ojrszqhCoqkyGxxXvU8vB/mrYXRbTMNU85 /aFRpD5qjEjmODHvfmk/i5P9PJJGpMG3uJfg6txc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1796951AbgJ0P2g (ORCPT ); Tue, 27 Oct 2020 11:28:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:35260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1796956AbgJ0PUr (ORCPT ); Tue, 27 Oct 2020 11:20:47 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2358421527; Tue, 27 Oct 2020 15:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812046; bh=QElG1aAp5okCuT19usec8CSs9Gw/L67dK4qjvYH3PIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zuxMlO6V5cmS0RULzKBXV/NTFwMv5c47ewuT9/7TfTM+9ILZ+g3VhfTvmHLr300C7 0jhzx5NJL94PHCLc+EjniAJhgugef/qmXOuM7j0KEYWKsRC7IsH6e7FEE96Dfsh8X2 anTp9ZnCu2Zy/KRfnTPmBo3gqIaFhqvAMJu9p5Ss= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ji Li , Ke Li , Eric Dumazet , Jakub Kicinski Subject: [PATCH 5.9 043/757] net: Properly typecast int values to set sk_max_pacing_rate Date: Tue, 27 Oct 2020 14:44:53 +0100 Message-Id: <20201027135452.550189264@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ke Li [ Upstream commit 700465fd338fe5df08a1b2e27fa16981f562547f ] 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 Signed-off-by: Ke Li Reviewed-by: Eric Dumazet Link: https://lore.kernel.org/r/20201022064146.79873-1-keli@akamai.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 3 ++- net/core/sock.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4354,7 +4354,8 @@ static int _bpf_setsockopt(struct sock * 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; --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1176,7 +1176,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) &&