From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] block: fix calling cdev_get_block_device with partitions
Date: Mon, 10 Oct 2022 08:38:34 +0200 [thread overview]
Message-ID: <20221010063834.2110400-1-a.fatoum@pengutronix.de> (raw)
For partitions, cdev->priv references the parent block device.
Doing the pointer arithmetic in container_of will result in an
out-of-bounds access. Do what the rest of the code does
and access cdev->priv instead.
Fixes: 84173bf3d0cc ("block: set S_IFBLK for block devices instead of S_IFCHR")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/block.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/block.c b/common/block.c
index 19bb81df2c3d..a4cfd6e22771 100644
--- a/common/block.c
+++ b/common/block.c
@@ -366,7 +366,7 @@ struct block_device *cdev_get_block_device(struct cdev *cdev)
if (!cdev || cdev->ops != &block_ops)
return NULL;
- return container_of(cdev, struct block_device, cdev);
+ return cdev->priv;
}
int blockdevice_register(struct block_device *blk)
--
2.30.2
next reply other threads:[~2022-10-10 6:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 6:38 Ahmad Fatoum [this message]
2022-10-10 7:14 ` Sascha Hauer
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=20221010063834.2110400-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox