From patchwork Thu Mar 7 14:23:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585761 X-Patchwork-Delegate: kuba@kernel.org 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 5834712AAFD; Thu, 7 Mar 2024 14:23:52 +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=1709821434; cv=none; b=TOcKhVQw0hgkJlpaXZMA5UimfLL9dMg/bIYYvZYSt/GrAV5NJwNz9RZiacPijoKNLiDcVaXwMtHlxKpiBWyv9vI4y2mUqlTOTecC9xtKrF8R1fvBG+grw7n2ZI/icKd0A1hQlPXdwkPYzOOLyvinioqeK3mM0eHmcGfEdxrnJz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821434; c=relaxed/simple; bh=58Vi20+IOZegSmkJsjvP31zlo1I+IWOSZUs2BECCUmQ=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=q7m7dM2SQ1oMrhyh3ga8zWk1aWAB0bMxYk0VqeT7pjqAHWqoWH81CffCgJZzJewJa6MfHJuriiwFCNndNOZP9WGCyNxZ0HAvFNJgRcjMobd/CWJUdQu4dIljnYbDO1x1khzeTIqLW6Gxg4WljtObqqOfdrlzXeqGVK3ZIm6oUSQ= 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=OgaYGJi/; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="OgaYGJi/" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 6C74414B179F; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 6C74414B179F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821430; bh=nG3okypY+wh5+yhVmWkAdCJ6RNrt8IrH6LYqUsbjAY8=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=OgaYGJi/QVZsuV8RtAESMRsj/4a4eXdOvxZRdKDH9FnMWj2TH5gFp53+FHI13035R cTCVJ9+9w1gfEFUIM3m3EmCTSU0JgkJeQBtKSrvwpJt3ynBvWR60VYQ+a7NCD31T/W HMoLrHfbcgVH0CEWXa2w9IeQDLcZSfOwZYXE+ARk= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 69FEA31923A8; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) From: Gavrilov Ilia To: Eric Dumazet CC: "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , "Simon Horman" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net-next v2 1/6] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Thread-Topic: [PATCH net-next v2 1/6] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Thread-Index: AQHacJsSTBdVqUkgdUuyCCq/rsgplw== Date: Thu, 7 Mar 2024 14:23:49 +0000 Message-ID: <20240307142030.2708698-2-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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 --- V2: - reword the patch description 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; - 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; From patchwork Thu Mar 7 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585765 X-Patchwork-Delegate: kuba@kernel.org 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 A4C0912D745; Thu, 7 Mar 2024 14:23:52 +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=1709821435; cv=none; b=KxQgsfD7QZlf2jOH6s3rGLdfJ9McvchUE13coP/kV9iwjkTlq8C7t0pEmAdrYhlKeoOaPZ6qQStlAj0qheswNM0tjo/exh2addlkMBV3ksSW0rQA4EZuDnjXChnB8GyltXOw/ZleDPtTG2zhGrbHjL5cr9IiWda+o2MXJhsVfaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821435; c=relaxed/simple; bh=CEXkOS+mriQWsWIUYob9llJ3dlmRIkZyGVNcMX66MRQ=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=B4MGGbLbo1nDpGED9LGHD5fVdUOO0Ib2SeSG0q10y0P64KU+6GFn5knKLwr3pgwfM0XhorHMhNxASF2wtxGdkUoG/unmWjc66MATYz4juiwH1GAHh2k8k+JWkqh6hhnwnHAGefbcXCemt3scu4jxPJTRrNz3mbkdcs4pf23Grr4= 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=BHDg436W; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="BHDg436W" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 9E4EB14CD2A3; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 9E4EB14CD2A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821430; bh=jwhtPOdDBSnbts5GSh1Hp50/yNRBHBaJHIGVXA5KGK0=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=BHDg436WgP0hlp57M+1zZLDvLpDPdST9IJk9inpZGrX3QoU1kwxYrleLbqICi3gHL QoEcogViHS5b3jihvPMxcSvvQah2x3IVQR3IncyCBLChMWIW8mkV3lThxCGtFeRFcB zfKdKlkla7/N2Kan8Ym2UplTiwMxvq5/NX7CoPpA= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 9979431923B0; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) From: Gavrilov Ilia To: Willem de Bruijn CC: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" , Simon Horman , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" , "Willem de Bruijn" Subject: [PATCH net-next v2 2/6] udp: fix incorrect parameter validation in the udp_lib_getsockopt() function Thread-Topic: [PATCH net-next v2 2/6] udp: fix incorrect parameter validation in the udp_lib_getsockopt() function Thread-Index: AQHacJsSjDbf8+7IiEaacwBYhQfFYA== Date: Thu, 7 Mar 2024 14:23:50 +0000 Message-ID: <20240307142030.2708698-3-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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") Reviewed-by: Willem de Bruijn Signed-off-by: Gavrilov Ilia --- V2: - reword the patch description net/ipv4/udp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index e474b201900f..17231c0f8830 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2792,11 +2792,11 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname, if (get_user(len, optlen)) 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 UDP_CORK: val = udp_test_bit(CORK, sk); From patchwork Thu Mar 7 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585763 X-Patchwork-Delegate: kuba@kernel.org 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 C26C512DD9D; Thu, 7 Mar 2024 14:23:52 +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=1709821434; cv=none; b=g47yxNeQ1np9TDMKLsdDV8TFIH1WuwgNCxX/TgJOxiEidhOeDxJ4tMtxiKyVeQsQqnJ2HporFi1tBmhFUXdHmXBDICxb+al95pmyQFSAFxVa/+Jr0hDbrT293IGH/otgHTHEl3unTw4KCLEOFuQyUw14rUzHisMdKZyFE4XyvWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821434; c=relaxed/simple; bh=ChQXRpwQELyvHAFX/iadZ4yeeIBqSARJLP39NfiniaQ=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=L7/yjUFtpNgo6rVPT8Ho3u5qSyJCQmUjRlAD+5Z5Zd1jabZBAcB2vQy2ZB1nuaDaWQ+S6JCo4h0iYfrEbb7tr/Bz38E116JlYalNp4DxAvh3lnUb/Lp4p+dYWTVx17XDpOhiHVNo5xZ4ixZ7BftuFz0O7PTHO5JNOkqiYl+cR/Q= 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=KaI0YFnB; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="KaI0YFnB" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id C7DF914CD2A0; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru C7DF914CD2A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821431; bh=JlK7qCntpJ/p8v06/wnF7QlyRzkrv0bD0v63q5kAbLQ=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=KaI0YFnBZFhtKtNC82wEzOLMnENDbn71eu2VlZYqsZUi/Fwd/XUUOf8Cq/RkxdL6j vA6iIwOfzmHNwcaqMc2+bbPzw+Tr8c83faAcKg1m+7Ci3s6MlURQq/Cbnwr62tBGbP Su8XlyTdaKq3p3y3NkmhUpv8M0KNW7NqQY/O7Dpc= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id C5CC431923B6; Thu, 7 Mar 2024 17:23:50 +0300 (MSK) From: Gavrilov Ilia To: "David S. Miller" CC: David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Simon Horman" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net-next v2 3/6] ipmr: fix incorrect parameter validation in the ip_mroute_getsockopt() function Thread-Topic: [PATCH net-next v2 3/6] ipmr: fix incorrect parameter validation in the ip_mroute_getsockopt() function Thread-Index: AQHacJsTKFrMydi/2ECGLiuYnS8e1w== Date: Thu, 7 Mar 2024 14:23:50 +0000 Message-ID: <20240307142030.2708698-4-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org The 'olr' 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 'olr' 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 --- V2: - reword the patch description net/ipv4/ipmr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 362229836510..b53c36c473a5 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -1603,9 +1603,11 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, sockptr_t optval, if (copy_from_sockptr(&olr, optlen, sizeof(int))) return -EFAULT; - olr = min_t(unsigned int, olr, sizeof(int)); if (olr < 0) return -EINVAL; + + olr = min_t(unsigned int, olr, sizeof(int)); + if (copy_to_sockptr(optlen, &olr, sizeof(int))) return -EFAULT; if (copy_to_sockptr(optval, &val, olr)) From patchwork Thu Mar 7 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585764 X-Patchwork-Delegate: kuba@kernel.org 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 540EF12DD9F; Thu, 7 Mar 2024 14:23:53 +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=1709821434; cv=none; b=gxCGHrKtCw2+SvUT0vVKHfWO3LH2XwPVR84R93gvbabRhq0OqH/pF/t65mwkSkDh0tps+24lUcE+PkRPbcnCqdWCZR788+pvoL6bFsURW8/DHf1zikGL1Fy9KSPsuFIruqMq614g+n5nR5BY4sNrePGdQHnj8cdb1GA0UNZ/6zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821434; c=relaxed/simple; bh=g4ZkBhJpsWE0qSkIlEwHDqZ9TzttHbtsGqgkmkuhIn4=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=HwZLJ9yO+NCCqAYubsdVIduqMTXnFTcyyCUeoWhnHMgXQB6O7XBwUeURxScdsuKlx57Vxp0VpxjxpTVQLgWoxlNxDFhBhTt15qA4ZNBJY/REZt34dEdsjvUA1RvwA7m2a7feMUP7fRA77mCJQOnoPZS5dIKlQ+NDVARxl14fo6g= 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=E1JahAPK; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="E1JahAPK" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 089A914B178F; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 089A914B178F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821431; bh=O5iwhDlAepukVWY+P4hL2O/eL/fnQyj+EFmoAC/Re8A=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=E1JahAPK0CqY8DUAK4d2ZSsy2OsZvwR6STJZaWb5Gjnaphk+4VGix8nhPhXN376Qb tHZK/9bByO4t+GOXk58zi3BtsCcaj/cXrx8T3dkpglThq7pmFbBhdnhamV75HDQMOh WF4Mhi/7/xctG9d27cuw4kUNItsENqjFt1b8jgmU= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 026C531923B0; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) From: Gavrilov Ilia To: James Chapman CC: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" , Tom Parkin Subject: [PATCH net-next v2 4/6] l2tp: fix incorrect parameter validation in the pppol2tp_getsockopt() function Thread-Topic: [PATCH net-next v2 4/6] l2tp: fix incorrect parameter validation in the pppol2tp_getsockopt() function Thread-Index: AQHacJsTzWqvqc9TOk22k8aDbIup9w== Date: Thu, 7 Mar 2024 14:23:50 +0000 Message-ID: <20240307142030.2708698-5-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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: 3557baabf280 ("[L2TP]: PPP over L2TP driver core") Reviewed-by: Tom Parkin Signed-off-by: Gavrilov Ilia --- V2: - reword the patch description net/l2tp/l2tp_ppp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index f011af6601c9..6146e4e67bbb 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -1356,11 +1356,11 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname, if (get_user(len, optlen)) return -EFAULT; - len = min_t(unsigned int, len, sizeof(int)); - if (len < 0) return -EINVAL; + len = min_t(unsigned int, len, sizeof(int)); + err = -ENOTCONN; if (!sk->sk_user_data) goto end; From patchwork Thu Mar 7 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585766 X-Patchwork-Delegate: kuba@kernel.org 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 C9FDE12F38E; Thu, 7 Mar 2024 14:23:55 +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=1709821437; cv=none; b=DZNC0OW55ozbiWPa81mW+zhxRcAZRnIhI81vTLuvetzqwdTIz7EW/EuhznNJilwvOb58wpUtgW7uJn/Su80bIyjumEC1fZA0BOn++sdx2NAbRJoKCBzpbwZWk5sOkZq9wEpy/vQi0kKDSx5o2MDZffbmFCtQB2NQepguSDrOeVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821437; c=relaxed/simple; bh=ik4mZx5M3IIhRc3Lmc3wxa3pGWHfYhX4OQNjFJzgBtw=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=k4S9tz7xtXfWHFmoutkoyc70YXFbXdLZGhmPPPJCIvFb56nkTwp8Jb1UkdCnCQAQ/ipsCsuJcQ+vxDJriOC1h0/LqmDbiDco/UjieaLVcdF/+EQ4CfWebYyQ9VwdD2NldRGs7sQAGA21T4G5rowXHO7SxP07RGqVDcYZzXvwaM8= 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=oGEL0RdJ; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="oGEL0RdJ" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 45FAD148BC8D; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 45FAD148BC8D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821431; bh=wLBmuF843sLrgBGQEjfgUIwkJeOumtJJVkyPbV28dCU=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=oGEL0RdJXnZ2QgcH7GThdeDY4Ws4sAGVkwJ3hwANuvMK6nKdFIsz/9n9qq7fetTkx Zrb77yOGtxB4a7BTa6LJ3CEQRXtUY/8AmAQDql8H7JCu+TUNmi4/nG4iPXkrUgpUcE zMVrjPWkoI8L4NDz5IIAsQZdNQHrQ4LSKUm+Xe78= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 43BE831923A8; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) From: Gavrilov Ilia To: "David S. Miller" CC: Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Howells , "Shigeru Yoshida" , Mina Almasry , Kuniyuki Iwashima , Tom Herbert , Simon Horman , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net-next v2 5/6] net: kcm: fix incorrect parameter validation in the kcm_getsockopt) function Thread-Topic: [PATCH net-next v2 5/6] net: kcm: fix incorrect parameter validation in the kcm_getsockopt) function Thread-Index: AQHacJsTlBzhET07pkKLeUDmE/Hj1w== Date: Thu, 7 Mar 2024 14:23:50 +0000 Message-ID: <20240307142030.2708698-6-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module") Signed-off-by: Gavrilov Ilia --- net/kcm/kcmsock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index 1184d40167b8..eda933c09792 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -1152,10 +1152,11 @@ static int kcm_getsockopt(struct socket *sock, int level, int optname, if (get_user(len, optlen)) 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 KCM_RECV_DISABLE: val = kcm->rx_disabled; From patchwork Thu Mar 7 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13585767 X-Patchwork-Delegate: kuba@kernel.org 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 E18F412F398; Thu, 7 Mar 2024 14:23:55 +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=1709821437; cv=none; b=WJzlJUUEl/OH+mHmMmZ/vAplUwQvv3TlSmTceJTlqViv3VPpFXwSSlCvHetjdy0Ck69iiEaLdxnaf908+C7aDpoQhgDo9Psf6+4BbBm+xvW+9V3qT0WmbHvtVPhRt0szabn015U5QvjsnrcQbkLlUrVvYh6TrCIuAw9bh50DThg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709821437; c=relaxed/simple; bh=vtO1NLo5DUmetb6YbznmKN592S3ILscEX8TxvmHk+mM=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=JhoV89O2m5DPjF2IyHNii1qKoTKDe3DX4Shy+lBv2g2MvJ40qvXWAOblkBRZAGVeSH0a7/uwrBMBkHDG6dpFxgnzt9eY2M9gMf54WRruOg8Z4SiDKBkvcDhr55aumHBPB01tKEZjYYRJODR5AZEZtKLWBTubLs8E/mCjkB47bbQ= 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=CSKC6bon; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="CSKC6bon" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 645FA14CD2C1; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 645FA14CD2C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1709821431; bh=TH5DEcHLIXFsRrfmZsIlzESb7JbDicH3qRJLGnlj6io=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=CSKC6bonPljDwT3yx3aRwX2VOnIFebvFMfc8W3Je1y75GndH5uCu9+Qm5tULHif98 ExnPzMWxYYjLPEmSQoo6dgI5+fwQSyGVs4XIJ+wuVLyob84qrQZOuCh6ysmRF50htN zM/YIQMiAvcFzinAbhKliDCNSXfMk2LeMLlf3INw= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id 60E2231923B0; Thu, 7 Mar 2024 17:23:51 +0300 (MSK) From: Gavrilov Ilia To: Martin Schiller CC: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , "linux-x25@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" Subject: [PATCH net-next v2 6/6] net/x25: fix incorrect parameter validation in the x25_getsockopt() function Thread-Topic: [PATCH net-next v2 6/6] net/x25: fix incorrect parameter validation in the x25_getsockopt() function Thread-Index: AQHacJsTcTQB2aBL6kWXuOtcpnTzVg== Date: Thu, 7 Mar 2024 14:23:50 +0000 Message-ID: <20240307142030.2708698-7-Ilia.Gavrilov@infotecs.ru> References: <20240307142030.2708698-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240307142030.2708698-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 Precedence: bulk X-Mailing-List: netdev@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/07 13:22:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/07 10:14:00 #24028863 X-KLMS-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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 --- net/x25/af_x25.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index f7a7c7798c3b..d18d51412cc0 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -460,12 +460,12 @@ static int x25_getsockopt(struct socket *sock, int level, int optname, if (get_user(len, optlen)) goto out; - len = min_t(unsigned int, len, sizeof(int)); - rc = -EINVAL; if (len < 0) goto out; + len = min_t(unsigned int, len, sizeof(int)); + rc = -EFAULT; if (put_user(len, optlen)) goto out;