From mboxrd@z Thu Jan 1 00:00:00 1970 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 9676B6FA1 for ; Mon, 3 Apr 2023 14:27:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AEAFC433D2; Mon, 3 Apr 2023 14:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680532068; bh=ADgOMX62IrR82V6veE+B2pFtCQ5XlrDFYKj5HOS6t58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lwA6Gc8AR4d35KNBG2Vonj6zXMJgIeRumN6xcaYdg78vCRjZ5CJbhnUeK23qEu37S /HFc0RyL+Cqc5NpoIjO8jt8cBJWLpezaqYMAZDf4LPB/NPeBOwMzAoFVkNUPVdobCG KJlvHfMpc4loBTiNTLQoChMbnI8441Tspk2zoHCM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , NeilBrown , Song Liu , Sasha Levin Subject: [PATCH 5.10 113/173] md: avoid signed overflow in slot_store() Date: Mon, 3 Apr 2023 16:08:48 +0200 Message-Id: <20230403140418.100115401@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403140414.174516815@linuxfoundation.org> References: <20230403140414.174516815@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: NeilBrown [ Upstream commit 3bc57292278a0b6ac4656cad94c14f2453344b57 ] slot_store() uses kstrtouint() to get a slot number, but stores the result in an "int" variable (by casting a pointer). This can result in a negative slot number if the unsigned int value is very large. A negative number means that the slot is empty, but setting a negative slot number this way will not remove the device from the array. I don't think this is a serious problem, but it could cause confusion and it is best to fix it. Reported-by: Dan Carpenter Signed-off-by: NeilBrown Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- drivers/md/md.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index c0b34637bd667..1553c2495841b 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -3207,6 +3207,9 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len) err = kstrtouint(buf, 10, (unsigned int *)&slot); if (err < 0) return err; + if (slot < 0) + /* overflow */ + return -ENOSPC; } if (rdev->mddev->pers && slot == -1) { /* Setting 'slot' on an active array requires also -- 2.39.2