Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2361317lqp; Sun, 24 Mar 2024 15:45:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwgJNT2ntKJn0zoJ+NNY82v1ZmwMsXI/2fJ4/pwoqxEPNgDfVOsRJTu/0dnZduwJtEnl9lNgTwsLJRt5PbhknNY7Jkan4wbXrtKUARDA== X-Google-Smtp-Source: AGHT+IG4/4TbgWTpwqT7Ltt6evxtktsL5w56ScTYr4Nrca7XM7MjBUJoKoBjIEI0kcdwWKmsAyR9 X-Received: by 2002:a05:6a20:3baf:b0:1a3:2f19:36b with SMTP id b47-20020a056a203baf00b001a32f19036bmr4019972pzh.24.1711320314028; Sun, 24 Mar 2024 15:45:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320314; cv=pass; d=google.com; s=arc-20160816; b=04LKccPc+da4IZ2fxAmd4LqQlU4Hf4+MR8kFT3s9VlEYUNvJKr1bjbaGgAJ5x1tD7z y85tZ0Y6IELQvhx05xXieCO6we5SdzgiX4qNgim8efzcwNpeVJkOSzkeG/F4tAmMKLD8 ivOrEQw1/2tI/ozJS881RQiTxFsieeue48isx5sEiZ5y8hXpYCZ5qacgxDWAQ0L+sI5l Z61FfAvjvUwcc6AwF13RC7bIecEL/zeMyXUZz+TtyP2PhCCCrkaKqwW8PKkdilA71+cw XiaOYle4AWoIgmfj/z5c2z3LNdhzlwiX25v3OVgFRrsdMNUOb/WbkjAZrUF7oR8706rC RuTg== 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=2xHxHygSAnQrBW199VXxvuVjPgpcb4/c7BiJOvxePnY=; fh=WHUOW1t0TQTTp4y4kg4u2DyZ0R00F7CEDJv/Qn5ppdI=; b=t93m6OzG/+VVv3cUStUweJuoaCVtBaqeZLcQo//I/Y2H3yTdu9GRIKBP1Y/taMwGxB IZxWxI2TsltFbnIvFtzaearwNWeKm2ng1pwA6Vxyovjck6KzmpPPcixLfq69Hi1CW6mX 2LQtwnr35v7wgy7COg/ajEIRyxwGoaw2Wg/i8t8JOftLMsquFEU2dJiYURVBbuovFt9Z 9LwYmawbFbS4oZRbwXy0wZ9y/FRsI9Vh5I/f3GbGrPpuBN8WMeoruKcXKvaIjLgU4AUE Hxeibcp7fNS8HxH1+BBiKfvB2oeGT8ohvLBY1qYmPLQiNiXxc6IjV9Yx+2z3i3Zbtkv1 kzKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fuEoHIDY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112928-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112928-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. [139.178.88.99]) by mx.google.com with ESMTPS id f1-20020a170902e98100b001e0a064788dsi3819692plb.529.2024.03.24.15.45.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112928-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fuEoHIDY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112928-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112928-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 A809828140B for ; Sun, 24 Mar 2024 22:45:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73B3C7350E; Sun, 24 Mar 2024 22:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fuEoHIDY" 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 907CD7172B; Sun, 24 Mar 2024 22:35:40 +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=1711319740; cv=none; b=qtjTdWF7+Rzz/LSHkvGSXzPpgy2qpBP6shg6wOfLEtQtaxlevTjy8bYmPPd6hfaXbO+1TYU/+5sSpuRUuZk1rNMp7rbw3d49FU8eRM/PsSpqT6QdH9vH7doCTV6O1f9kYZGbaVLefrzzy/UBsBJo9A5IvIz9e8d+ZVigPGWeRaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319740; c=relaxed/simple; bh=+mRypTj2AN+uFrmsMst73xXavbGCXAj069qIzrAjzZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nqm0uwJ4YiwHDVJOzWiPtmaM4bApbk1tJHN7tzRBWU9ftmBA/mlwEVINIEaV5y5Ulq/wgBgjaP2P4kDcNpPqU/ZAamxsd9IdJy3fjFqKrO3ebtZ0SCmAMt8Qfn08OAFn7T9VhBprokill125pHghTcjY/MRz49gZ1uSG78nKZco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fuEoHIDY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66339C43399; Sun, 24 Mar 2024 22:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319740; bh=+mRypTj2AN+uFrmsMst73xXavbGCXAj069qIzrAjzZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fuEoHIDYd2Et/hDtJ+r072Bm7rwYTo+R/HhliPb+cUeIqtXCx9/iXMkuOhwR0klEL 7Q1OzTI/4SLjKAdEaLTHq075nh94Vr/s3SRPAxPYqkK6ES1Xg/5HKxn2g2juMEzWfM 4+QSH0ZuO+7YI1Vfy3Qc6ePZWtbnws972UKVARKY6gSIoaAh3+yG6IAyGy5K8dzCbe AL++iwPTgn/Me7uMHLNPbRz126NpClBzrOoZEHcibRPSvb99NUJK74bwOavMCZ9D9O ObnAOMRNWpI4cg6QrzhrMtaFySmQ2mlxy5rQZ0GouF7xnHEbRGicG1etF69mcMlmBr C8qDfR8EPiv2A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , Jens Axboe , Sasha Levin Subject: [PATCH 6.8 041/715] io_uring/net: fix overflow check in io_recvmsg_mshot_prep() Date: Sun, 24 Mar 2024 18:23:40 -0400 Message-ID: <20240324223455.1342824-42-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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: Dan Carpenter [ Upstream commit 8ede3db5061bb1fe28e2c9683329aafa89d2b1b4 ] The "controllen" variable is type size_t (unsigned long). Casting it to int could lead to an integer underflow. The check_add_overflow() function considers the type of the destination which is type int. If we add two positive values and the result cannot fit in an integer then that's counted as an overflow. However, if we cast "controllen" to an int and it turns negative, then negative values *can* fit into an int type so there is no overflow. Good: 100 + (unsigned long)-4 = 96 <-- overflow Bad: 100 + (int)-4 = 96 <-- no overflow I deleted the cast of the sizeof() as well. That's not a bug but the cast is unnecessary. Fixes: 9b0fc3c054ff ("io_uring: fix types in io_recvmsg_multishot_overflow") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/138bd2e2-ede8-4bcc-aa7b-f3d9de167a37@moroto.mountain Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- io_uring/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 1d9bfde71809a..058e04ea68c04 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -544,10 +544,10 @@ static int io_recvmsg_mshot_prep(struct io_kiocb *req, if (unlikely(namelen < 0)) return -EOVERFLOW; - if (check_add_overflow((int)sizeof(struct io_uring_recvmsg_out), + if (check_add_overflow(sizeof(struct io_uring_recvmsg_out), namelen, &hdr)) return -EOVERFLOW; - if (check_add_overflow(hdr, (int)controllen, &hdr)) + if (check_add_overflow(hdr, controllen, &hdr)) return -EOVERFLOW; iomsg->namelen = namelen; -- 2.43.0