Skip to content

Commit

Permalink
generic: deny write to uImage.FIT sub-image partitions
Browse files Browse the repository at this point in the history
Set policy bit to force read-only mode on uImage.FIT filesystem
sub-images mapped as block partitions by the FIT partition parser.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  • Loading branch information
dangowrt committed Jan 11, 2022
1 parent 8cdc356 commit f2c3875
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion target/linux/generic/files/block/partitions/fit.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
strlcat(state->pp_buf, tmp, PAGE_SIZE);

state->parts[*slot].has_info = true;

state->parts[*slot].flags |= ADDPART_FLAG_READONLY;
if (config_loadables && !strcmp(image_name, config_loadables)) {
printk(KERN_DEBUG "FIT: selecting configured loadable \"%s\" to be root filesystem\n", image_name);
state->parts[*slot].flags |= ADDPART_FLAG_ROOTDEV;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
--- a/block/blk.h
+++ b/block/blk.h
@@ -361,6 +361,7 @@ char *disk_name(struct gendisk *hd, int
@@ -361,6 +361,8 @@ char *disk_name(struct gendisk *hd, int
#define ADDPART_FLAG_NONE 0
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2
+#define ADDPART_FLAG_ROOTDEV 4
+#define ADDPART_FLAG_READONLY 4
+#define ADDPART_FLAG_ROOTDEV 8
void delete_partition(struct hd_struct *part);
int bdev_add_partition(struct block_device *bdev, int partno,
sector_t start, sector_t length);
Expand Down Expand Up @@ -73,13 +74,16 @@
#ifdef CONFIG_SGI_PARTITION
sgi_partition,
#endif
@@ -694,6 +701,11 @@ static bool blk_add_partition(struct gen
@@ -694,6 +701,14 @@ static bool blk_add_partition(struct gen
(state->parts[p].flags & ADDPART_FLAG_RAID))
md_autodetect_dev(part_to_dev(part)->devt);

+#ifdef CONFIG_FIT_PARTITION
+ if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
+ ROOT_DEV = part_to_dev(part)->devt;
+
+ if (state->parts[p].flags & ADDPART_FLAG_READONLY)
+ part->policy = true;
+#endif
+
return true;
Expand Down

0 comments on commit f2c3875

Please sign in to comment.