All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: NeilBrown <neilb@suse.de>, Dan Carpenter <error27@gmail.com>,
	Song Liu <song@kernel.org>, Sasha Levin <sashal@kernel.org>,
	linux-raid@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 01/12] md: avoid signed overflow in slot_store()
Date: Wed, 22 Mar 2023 16:01:55 -0400	[thread overview]
Message-ID: <20230322200207.1997367-1-sashal@kernel.org> (raw)

From: NeilBrown <neilb@suse.de>

[ 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 <error27@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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


             reply	other threads:[~2023-03-22 20:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 20:01 Sasha Levin [this message]
2023-03-22 20:01 ` [PATCH AUTOSEL 5.10 02/12] net: hsr: Don't log netdev_err message on unknown prp dst node Sasha Levin
2023-03-22 20:01 ` [PATCH AUTOSEL 5.10 03/12] ALSA: asihpi: check pao in control_message() Sasha Levin
2023-03-22 20:01   ` Sasha Levin
2023-03-22 20:01 ` [PATCH AUTOSEL 5.10 04/12] ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() Sasha Levin
2023-03-22 20:01   ` Sasha Levin
2023-03-22 20:01 ` [PATCH AUTOSEL 5.10 05/12] fbdev: tgafb: Fix potential divide by zero Sasha Levin
2023-03-22 20:01   ` Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 06/12] sched_getaffinity: don't assume 'cpumask_size()' is fully initialized Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 07/12] fbdev: nvidia: Fix potential divide by zero Sasha Levin
2023-03-22 20:02   ` Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 08/12] fbdev: intelfb: " Sasha Levin
2023-03-22 20:02   ` Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 09/12] fbdev: lxfb: " Sasha Levin
2023-03-22 20:02   ` Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 10/12] fbdev: au1200fb: " Sasha Levin
2023-03-22 20:02   ` Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 11/12] tools/power turbostat: Fix /dev/cpu_dma_latency warnings Sasha Levin
2023-03-22 20:02 ` [PATCH AUTOSEL 5.10 12/12] tracing: Fix wrong return in kprobe_event_gen_test.c Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230322200207.1997367-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=error27@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.