Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2489221lqp; Sun, 24 Mar 2024 23:14:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRzuyzlr9vRwZUvJFI/jK73qbEd7fEKL1fk5Tb0ablCLFr2o6ijLJyKEb09hEK9AGyQ+DHlPtY0gSm/H7X+96i2u3lqTAXvot7ug50Zw== X-Google-Smtp-Source: AGHT+IERq2soPZnVDahpaj49mOwGNbAxZCOOPnUwDi4hXmunDj+2+EHD0k3ij/6XYcREkdfFlWWf X-Received: by 2002:a17:90a:53a4:b0:2a0:7a97:fa6 with SMTP id y33-20020a17090a53a400b002a07a970fa6mr207127pjh.5.1711347285397; Sun, 24 Mar 2024 23:14:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347285; cv=pass; d=google.com; s=arc-20160816; b=EhI0/9CUoCNEe9WNS9ofWKpFIWouSmIhkcjR3jU35zNGQ6oCTNMQezuerOqPxfQiqt B6r0xSoWuGbDEY73NJwg6ErRMmcy7s+NUuSIlzgue9fAaKjL5VEBbjD+/nba565MfLBu LmfoSddmP4KN0vViXZ8w4HtdURP6MsiMgJRUP8Zcg9Q43YT8QGZ64cKubfZOFhZ4kUUg McESWNKFRmmx9yLsAoTr4LZgM6n/m7VZ4qjnJLyfyETRquWDWeJZYjLGQO8/87Y0vB7p nDGCzlSIkAaiC1EM2XmNrR2g9BI4I8F2iS6r8WPz2kQWaLTLyUSYqqnMZDAwyEbgBe/+ lHpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Yztu1tmk0TLG5sq40PELzYtFaOwmflVl0uBf46SOP00=; fh=Md7EcTWe18BFLXa/NFjTdAq1RnNmcXYsjSXnwSOO/TQ=; b=HT/+eCCmd8ob3Cq6hx6q4wEkw3S3yggzagB5UxrxopLf3GGhAZT8ExdT5hnmgk3r8P gStIRFd5ikhFe/MCJj4VuhQ8E+w2zLgLzl6c0HM4R44b2cULWmaTTkB4GQ+5WwqY7zj6 Sggy07uaZjaStX/Rk//B+yA7gWKo6UTf0qtq2gu5SIY6JJtwdK7bYovaJOc/ufA0ZLYN CZBzAteNc/ca97Hidoh3VYPiew/mgPMpI1mBeQ2BHm/qBdtfW5EWwjG5Z4ZVw/sV4y6U lyGcMtTzkCbZ37qN0hP9Wgsdbsu80GX0RheMXMa2Qj5KX2y3QcUad52rDCOgAg4Q9zSV nJIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ub99mFR9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114522-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e10-20020a17090a77ca00b0029deba7c7b2si6955445pjs.0.2024.03.24.23.14.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:14:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ub99mFR9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114522-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D61A429168B for ; Mon, 25 Mar 2024 06:14:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86404182EF7; Sun, 24 Mar 2024 23:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ub99mFR9" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A503915B142; Sun, 24 Mar 2024 23:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322148; cv=none; b=fJKM9/h8zJmlHiK75CYVtQn1C6RxHFKYTz+eQcGCxc/7pvDM2ommMJWWFdneCa+rLj0bwF//8ay0sZq7yv75fe4bywKuvFb4Mka4gQ/KRksO91XgBL7s1LOmIrAZZVXrS1C6ITq8Ua7BWfUKuIIwpUOeRYIRSvfaPr6+Bb4ZRAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322148; c=relaxed/simple; bh=iBFdlvoaK/4k9N28EWGDTW5mTR6JAbLH0cIeNaIIj3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJhX+mBHOHLDaxCx8Zqut8uLKFltUsf419BtqXnMYz4+o9CRq00TlKFZja3z2cHqGjuZ2Ai1/bAtHdXX53KZcSRV1K10WczZkp3J5XC+qX9UiOaQNCJRt+zDXAu5GoZXdyCKPxFlnOBUNFe8t9KGfFO7daUJFgX/O+WmTxaa7Jw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ub99mFR9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F963C433F1; Sun, 24 Mar 2024 23:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322147; bh=iBFdlvoaK/4k9N28EWGDTW5mTR6JAbLH0cIeNaIIj3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ub99mFR9VMz+tpvPUb82F4E9AQDplG2QLQrpL39fRJRYM8lcaXkN1oaZFfovNo4US tlWnEuGvmgdYVjKbOnrHHvmWvC/+0VR2XghU22UDaPbQD5CJZ4QtLvmhUELdG3Nadu PVPSZrV+o70Jdj2Y5iaabtgvSSm/kbPBuEIVBxcifaHUldzurvzEsmu46VQ/kwBTof GO6DmjL54DMMJUBymBwqS2oyvN5P9EGbPTevCLCRxPRJCkLWiKxziXygCHsr4nbm0i rN9u+7JsJyGLW0AfUf1mw/2Y0T+QlPZ6xbOLBAgNf0iCMvkHaBbZYEUchHoyhJ3LEG me2jcXZJMRYGA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gavrilov Ilia , Jason Xing , "David S . Miller" , Sasha Levin Subject: [PATCH 6.1 224/451] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Date: Sun, 24 Mar 2024 19:08:20 -0400 Message-ID: <20240324231207.1351418-225-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Gavrilov Ilia [ Upstream commit 716edc9706deb3bb2ff56e2eeb83559cea8f22db ] The 'len' variable can't be negative when assigned the result of 'min_t' because all 'min_t' parameters are cast to unsigned int, and then the minimum one is chosen. To fix the logic, check 'len' as read from 'optlen', where the types of relevant variables are (signed) int. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Gavrilov Ilia Reviewed-by: Jason Xing Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 86e7695d91adf..5a165e29f7be4 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4102,11 +4102,11 @@ int do_tcp_getsockopt(struct sock *sk, int level, if (copy_from_sockptr(&len, optlen, sizeof(int))) return -EFAULT; - len = min_t(unsigned int, len, sizeof(int)); - if (len < 0) return -EINVAL; + len = min_t(unsigned int, len, sizeof(int)); + switch (optname) { case TCP_MAXSEG: val = tp->mss_cache; -- 2.43.0