Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp965261lqs; Wed, 6 Mar 2024 02:05:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV25+vjsbqw3+pkBoL9hZVJgyaQg0UcjEskGm2r1q/0z5kXJ7m/5jOF+YrwsvWKIqc9xi2vWh3TsG2qnCwl/cNZqvRUbgk9tQqVTXDLDQ== X-Google-Smtp-Source: AGHT+IH0kBax4RocVb21QSdFdTfJQLvxQujxGawCsGHeuOG6exj1LX34mGC2cDoT2nyvhO/JYaqS X-Received: by 2002:a50:cac7:0:b0:564:b823:a78 with SMTP id f7-20020a50cac7000000b00564b8230a78mr10231141edi.37.1709719543825; Wed, 06 Mar 2024 02:05:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709719543; cv=pass; d=google.com; s=arc-20160816; b=vji6dmhpfrXnfOIL8vMkqAwf/SOQcjjdyzvhLpjf/Z1KcJvM7lEKd5jAHPRAUhGcUu qaGlJ5I0zH9wb06ycMcNzUx+ROBDrniuTRSl75Wlz6mTQHqEBggdmlgwjEPEAxHfzK7T 496mpPDpj/SlSN/bvxc52FDilWdoYtDiQ5L1QZmjP/w8+drsM7nsVFf96+9YPd9xuwRy UT4jBoWJlBsa68emJo8Y+fp57nMbCnpxur6m+q6MWEnBTGQDJzHdcBG9YnqkK1GjxVgJ Z2uqKiRHkeDYTCZRgbXY0n9pHwDWmJcwrcYon84X6CqXvT/ETN3XP9nXv8QwKDVTvOiR EkcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature:dkim-filter; bh=MO5pj3YzaettEmio8Z6W3c3zdCICCzph1tchXffqFi0=; fh=Ph+LAbJbqvEKVuxIF/szCdTuK2ufH2DmJ76Zt0cf1LE=; b=AwrVpTQ7VYhHRZZo8aAIHh1ixvspWzM7s5dWoZbKEyuHY7GmAqL7lVniPy37VQ/OZz nP4npQh8+A7pacJS1t9jUpCVIl3AXOYVBn3kLH+/ep7hYSZv51gK+MqYIZqa6se9LBw0 n+0Jk7/w2rgqGVp8eSWXg/pRe32aL5wG58vTdftxPEIgMC2JPiAS4bEAkYKI+8snMlS3 xHMBJiqZaKcOiwkj5Zhb4gQgZmPokJeUaP3Cg3YWKYFFsQo9W3swc5MDWtY+Bz+josQH 1pTItcZ5oZwxxnemD/IShfRaDGrGRvWU80iXOUnfdTjCABiWBJqPZhqHAQiFf4nqHPoX Yw0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=mi4Yy9F5; arc=pass (i=1 spf=pass spfdomain=infotecs.ru dkim=pass dkdomain=infotecs.ru dmarc=pass fromdomain=infotecs.ru); spf=pass (google.com: domain of linux-kernel+bounces-93700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y14-20020a50e60e000000b00567d5050cc7si747277edm.572.2024.03.06.02.05.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:05:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=mi4Yy9F5; arc=pass (i=1 spf=pass spfdomain=infotecs.ru dkim=pass dkdomain=infotecs.ru dmarc=pass fromdomain=infotecs.ru); spf=pass (google.com: domain of linux-kernel+bounces-93700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6CF391F2177D for ; Wed, 6 Mar 2024 10:05:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03F3D5F543; Wed, 6 Mar 2024 10:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="mi4Yy9F5" Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD0D85FB8C; Wed, 6 Mar 2024 10:05:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.244.183.115 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709719502; cv=none; b=UAJ/sNzDMcFMVCyebJl4Ddfif3IitXiAksnZ5kb6nHVvelSGnfasze/otuBKm2uHcAiXallXb0eVSTgk/LXSJm0YQHSRvrHZ1kcLskVEVt/3ELQtebRliuUxLv2x6ZdkiYTzxF7WJQ+lHDwcDXSSsYIDVNmIO7HBqrYCYGX0S6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709719502; c=relaxed/simple; bh=Xx6fuMijWmbCZ68HGYxzw2XFhSveMJbNuQ55fTD8vyM=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=jy8K7dUu1urXGN65F7xomN+Y/g/HZhaIefUORxgfqCgpNNK5XmQbjlIiKZHggCdXfzGpZSU3LKlviPiRNojZoRwUucLMJf3Ru+Ovjv+nIJ4vjehbTSNCgsANAzgoMwbN2PLFEdPiVT2YB4WJdy/D0dK8DX4ReceQE3OvJHAHIJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=infotecs.ru; spf=pass smtp.mailfrom=infotecs.ru; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b=mi4Yy9F5; arc=none smtp.client-ip=91.244.183.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=infotecs.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infotecs.ru Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id DEC201423784; Wed, 6 Mar 2024 12:57:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru DEC201423784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709719071; bh=MO5pj3YzaettEmio8Z6W3c3zdCICCzph1tchXffqFi0=; h=From:To:CC:Subject:Date:From; b=mi4Yy9F5aiqk54JaClW5h6c9Gec/kRoaj7FXX9qxryuWIghOXRki8XdrSsz5LVMBN EXog8AwH911oOB229tNkwriQu9b6EEzuzBmEMcHVES2XReqknLywhd9xJzA7s2/yEK u7mVLQD73atAokkuKX9UHUtm9dciPepvwaYCI2LY= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id DB8FD318FDDC; Wed, 6 Mar 2024 12:57:50 +0300 (MSK) From: Gavrilov Ilia To: Eric Dumazet CC: "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net-next] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Thread-Topic: [PATCH net-next] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Thread-Index: AQHab6y/ymlnx20eHUyJFqMhxuWaSg== Date: Wed, 6 Mar 2024 09:57:50 +0000 Message-ID: <20240306095430.1782163-1-Ilia.Gavrilov@infotecs.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-exclaimer-md-config: 208ac3cd-1ed4-4982-a353-bdefac89ac0a Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KLMS-Rule-ID: 5 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Status: not scanned, disabled by settings X-KLMS-AntiSpam-Interceptor-Info: not scanned X-KLMS-AntiPhishing: Clean, bases: 2024/03/06 07:48:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/06 02:14:00 #24008090 X-KLMS-AntiVirus-Status: Clean, skipped The 'len' variable can't be negative because all 'min_t' parameters cast to unsigned int, and then the minimum one is chosen. To fix it, move the if statement higher. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Gavrilov Ilia --- net/ipv4/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index c82dc42f57c6..a4f418592314 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4010,11 +4010,11 @@ int do_tcp_getsockopt(struct sock *sk, int level, if (copy_from_sockptr(&len, optlen, sizeof(int))) return -EFAULT; =20 - len =3D min_t(unsigned int, len, sizeof(int)); - if (len < 0) return -EINVAL; =20 + len =3D min_t(unsigned int, len, sizeof(int)); + switch (optname) { case TCP_MAXSEG: val =3D tp->mss_cache; --=20 2.39.2