mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: uol@pengutronix.de, ske@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 3/3] partition: reparse tables only if CONFIG_PARTITION_MANIPULATION=y
Date: Wed, 15 May 2024 10:05:07 +0200	[thread overview]
Message-ID: <20240515080507.4056255-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240515080507.4056255-1-a.fatoum@pengutronix.de>

reparse_partition_table() will delete a device's existing partition
cdevs and allocate new ones according to the new partition table.

Holding a reference to a cdev prevents it from bring removed to avoid
dangling pointers and use-after-frees.

Unfortunately, not all users call cdev_open on the cdev and increment
the usage count, instead using functions like cdev_by_name, which don't
call cdev_open.

The proper solution for this is probably to change all functions that
return a cdev to actually take a reference to the cdev.

This will involve quite a bit of work though, so for now, restore old
behavior by making reparsing of the partition tables dependent on
CONFIG_PARTITION_MANIPULATION=y.

The option isn't fully appropriate as partition manipulation can happen
by writing to the parent block device, but not noticing changes of
partitions is the behavior we had before.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/partitions.c |  2 ++
 include/disks.h     | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/common/partitions.c b/common/partitions.c
index 17c2f1eb281a..0b10377e7327 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -266,6 +266,7 @@ int parse_partition_table(struct block_device *blk)
 	return rc;
 }
 
+#ifdef CONFIG_PARTITION_MANIPULATION
 int reparse_partition_table(struct block_device *blk)
 {
 	struct cdev *cdev = &blk->cdev;
@@ -285,6 +286,7 @@ int reparse_partition_table(struct block_device *blk)
 
 	return parse_partition_table(blk);
 }
+#endif
 
 int partition_parser_register(struct partition_parser *p)
 {
diff --git a/include/disks.h b/include/disks.h
index ccb50d3ce94f..a3673d1e276f 100644
--- a/include/disks.h
+++ b/include/disks.h
@@ -3,6 +3,9 @@
 #ifndef DISKS_H
 #define DISKS_H
 
+#include <linux/types.h>
+#include <linux/errno.h>
+
 struct block_device;
 
 /** Size of one sector in bytes */
@@ -24,6 +27,14 @@ struct partition_entry {
 } __attribute__ ((packed));
 
 extern int parse_partition_table(struct block_device*);
+
+#ifdef CONFIG_PARTITION_MANIPULATION
 int reparse_partition_table(struct block_device *blk);
+#else
+static inline int reparse_partition_table(struct block_device *blk)
+{
+	return -ENOSYS;
+}
+#endif
 
 #endif /* DISKS_H */
-- 
2.39.2




  parent reply	other threads:[~2024-05-15  8:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  8:05 [PATCH master 1/3] cdev: return error code from cdev_close Ahmad Fatoum
2024-05-15  8:05 ` [PATCH master 2/3] fs: devfs: restore cdev reference count maintenance Ahmad Fatoum
2024-05-15  8:05 ` Ahmad Fatoum [this message]
2024-05-15  9:24   ` [PATCH] fixup! partition: reparse tables only if CONFIG_PARTITION_MANIPULATION=y Ahmad Fatoum
2024-05-16  7:13 ` [PATCH master 1/3] cdev: return error code from cdev_close 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=20240515080507.4056255-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=ske@pengutronix.de \
    --cc=uol@pengutronix.de \
    /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