Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp244616pxx; Wed, 28 Oct 2020 03:58:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+PjXn5p1qhZecfQmifz2o7ZaKgpPemxz1VZPp7uSeg4HRk/vq1zVRyj1PYy9cNj33412D X-Received: by 2002:a17:906:892:: with SMTP id n18mr6747596eje.1.1603882689360; Wed, 28 Oct 2020 03:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882689; cv=none; d=google.com; s=arc-20160816; b=mWaF8VCT4Yl8pRe6zIUbIQulIZ4G0Yv8bKmEQGdrSDa7B8tpUhH9SaLBNA2/sYneoY /9+9SC+5eOmjumXW/HSerR9UrQvMX6c/JqB4m/8APpXP6/rxSvLw/JYCk25wJ65pmXuz WykkFfPpk8OrSGYRwDtZ/s0JiiCPlI1S023qYXciZ5CflKqqmxHJKTvbW1qfmTEuaSpF nZM3Srh26Jn1IChTvVqbquzmWcZdRuEBQmJsJ++FpRZmhDOmWFX2HkDY8r4oGyZvrElI 9K+5IKxwOjOoSwXVJY8+t+e8wY4tu4NeSRulhI90+EORvVh3QtKAq4naFE6PxvIt2AaZ TFWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lLJgtgKH/AHCiZVkuBFuIkQcGBH0YridiIvGFCIpXK8=; b=S1loAlJ2qjKgNJRQAwZ8V9cdQXB4JzblbQb/KJ6iGC3B+vDXJwexGmjc1UCtfObF7R /JiIdUCYfaYzhuV4Lv7BM4gSkokMzE7BhYG8/xcxr2R/GxNeCwYV1iSbdt21bt+lIZlS NHHKOyw7sDOhV5EeDsPVs5b4Z/FV+I+9+sLzF4MEXDUF2pnzj2cpa1srlRO15/otKXKF MpJc8vWjQ1scPV6V0IoEHkNsPQIcQeBT32oKK9ELlNlIh5WTN92s0REH8lKyBDE41ce4 NjkxzMV62ul933dU3/cCFdpno6t0v+BBVsM5Mb95z5FHYH9oqYYVpprO7hzhBsdARMxM wn4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9z07w7z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si2741759edu.169.2020.10.28.03.57.46; Wed, 28 Oct 2020 03:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9z07w7z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782132AbgJ0O4l (ORCPT + 99 others); Tue, 27 Oct 2020 10:56:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:50328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1772985AbgJ0Oup (ORCPT ); Tue, 27 Oct 2020 10:50:45 -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 8DA54207DE; Tue, 27 Oct 2020 14:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810245; bh=TOMOFqJJWaTID7t4W5xrrfYitBkfSAsctATwSlD6NFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9z07w7zC4kcqYJrACeFK5SDFe+ZVH5BUm5wXvcBmdTg1ZmCBiUymOtJOc1pb+UKc Ut4G+DCbEefO8UQaJzrehIDyN3FBZY8KP21LEmZodZWkkhYMCOhWoDoRmwviZalYZA Y8H95eSrHIZtIkgyeW70sehkPk0v8D/xwrZyb3v0= 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.8 044/633] net: Properly typecast int values to set sk_max_pacing_rate Date: Tue, 27 Oct 2020 14:46:27 +0100 Message-Id: <20201027135524.767612610@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -4323,7 +4323,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 @@ -1184,7 +1184,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) &&