Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2556524lqp; Mon, 25 Mar 2024 02:29:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXU8JNgiuU9N4tqtSjD0ZgqfqccMxVfcXkkfhb+1XzXaTOxmVhw46fINEwKCW/GrRpSUrjGENZm50+AKQ/oTS6oQ4bMSrEWCpNVflxjWQ== X-Google-Smtp-Source: AGHT+IHZ5YaXXOrzmmgdBlpc2jrcTWj6BuJJB2HmK1is8EQnqrqcZA0W449r5/kyUYBhaGXVkF6a X-Received: by 2002:a05:6214:4017:b0:696:8505:1947 with SMTP id kd23-20020a056214401700b0069685051947mr5611452qvb.30.1711358974796; Mon, 25 Mar 2024 02:29:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711358974; cv=pass; d=google.com; s=arc-20160816; b=xracF3JHCppac/LTZKhg8NDAjy0/hJHbdPhWG48KZcnRmKt0H3IuhO/pfIBt8UkfLl I2pJkMA2ym0oNzBu/qnUSuTswmyn6Bq4wjbiK9fZKObVpqbfjB9EQCXvz1ZHsT2pQbml 14qHzeWRVpd3jh5oJ75lDSJAMAUGhErW6918mDl4bc/uUOFf4htjj5f5CkpxXyNPiscB OI4xSW6+VbU2MyrA5dc5vtx/fnVLz/DYj3xuwco13bCZtY6yDm+wvkOKdvSAGnTb2wbw k6XgPWTVq236aTWyL/YnzQhmWzCvV2eUsEXTbk4OA04Mm7VzdOg+b2Mr5NE1b3RMkcPN xUAA== 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=8pd9CeRGVrB8aFsk4AyojUCNYskE/Vh6fcMDbe0Wqs0=; fh=WHUOW1t0TQTTp4y4kg4u2DyZ0R00F7CEDJv/Qn5ppdI=; b=b3yaZZ97oVTdn2pV66uDA3Ho2SaroS8Xbdr2UMrW8eLF0priZqBCMe65w9o3WyXfhZ 7rswLSUO20eGDuqh0+NCPHkCPVLVs8g34kazSEiGK1+WMA7waYXAGqgz6kzs/jwE/rf8 YhIMDU1ln1L1pjHllaUknDiigYe728ox78e8PcjoNdry6Zz9yC1Pm+jJCfSem8YGgGGa E70pbchCpmNhavmknp9Tx2ooGS7WvjGUIH1XVMYv12g0wnfdw0R72V5HYKoCr7CgL5yR tvf3I7ONAa8EqOHwldwSIaFsEWfxnvZL/HAVI6CliZYLZHSpc2/23LfPNp6tYB4zZCP6 ioTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pE01mjdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 2-20020a0562140dc200b0069694dab3ecsi258837qvt.153.2024.03.25.02.29.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pE01mjdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115827-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 660921C315A0 for ; Mon, 25 Mar 2024 09:29:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 310D1378C50; Mon, 25 Mar 2024 03:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pE01mjdJ" 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 A0BEB145B08; Sun, 24 Mar 2024 23:13:22 +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=1711322002; cv=none; b=jM3oX5ydLXmvoyB0M0ly5xLlZmS5ogi7oPsMdAhCdYLx3K5OiuVQmoMck5NWCwLtZhrpNiUusiujNNfVGYFTqnuNUB7Yo6URLXSpSjRGrBxHd+4k6mr4zYNfogup+NMQaaT24qus25T0KGUXXfoaIFr3ZbGNuS+6rXjfQnopfcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322002; c=relaxed/simple; bh=YM583JOqL3MJ6EuDsJhsm1gHhxEzlRG5GuE0LdoPFlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mjJx5H3BfgvVg0JPkOofCoLiip1zHS5aOMLIsL9BdVxbkMAjh67xygTYQOkfM68MZkm8CtiYoKkiJxrCua0vDsFU6x1cSnuygRwUQyX24hJeBq7tXvjjANWC0j8ZQNdRNNO5aWNaSXnbooLpyVmjNW5GclV4kwzxaTYaRwF96HM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pE01mjdJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCC44C433F1; Sun, 24 Mar 2024 23:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322002; bh=YM583JOqL3MJ6EuDsJhsm1gHhxEzlRG5GuE0LdoPFlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pE01mjdJmwDetu2cNrCunVvujklWghdQ5wO5DBL9AUByYCSRFDLPUxfZAn+UGNRn7 Sf6J/zQ57tc9hrVwkdSVBgxZ/yhE66orPwYL59adc6obosTIyUZBvRGW7dJifeaA07 1Fb/Q1v8sni88VNX2mZXrTUFdo8TGBp5kcy9dyrbZ7dyrLUknpBRxs85x6gKrsWySQ lN6w2e0ephzxeUyGLNBLQA/m3bttvn+rHZ8rIOhwKrerYWqKW0d/1fdGpmSET/hmOj k9y2zbvW5EJ8x0NCm7qHIB1mZsm9bEdvXDzFD/FyA65iGFhOYT0NNt7F4mDCDk0i1v Gl03l+am1YBkQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , Jens Axboe , Sasha Levin Subject: [PATCH 6.1 074/451] io_uring/net: fix overflow check in io_recvmsg_mshot_prep() Date: Sun, 24 Mar 2024 19:05:50 -0400 Message-ID: <20240324231207.1351418-75-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: 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 b273914ed99f0..9fc0ffb0b6c12 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -524,10 +524,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