Skip to contentSkip to conversation

partitions/msdos: FreeBSD UFS2 file systems are not recognized

PATCH In review Richard Narron 3 participants 8 messages May 26, 2017 – May 27, 2017 1 message not in the archive Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 partitions/msdos: FreeBSD UFS2 file systems are not recognized

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

Though all 3 of these BSD systems use UFS as a file system, only FreeBSD uses relative start addresses in the subpartition declarations.

The following patch fixes this for FreeBSD partitions and leaves the code for OpenBSD and NetBSD intact:

---
Changelog v2->v3:
- Add Cc:
Changelog v1->v2: - Improve style, use +=

---
 block/partitions/msdos.c | 2 ++
 1 file changed, 2 insertions(+)
block/partitions/msdos.c +2 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
 			continue;
 		bsd_start = le32_to_cpu(p->p_offset);
 		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)
+			bsd_start += offset;
 		if (offset == bsd_start && size == bsd_size)
 			/* full parent partition, we have it already */
 			continue;
maintainer
#1 lore raw
Quoted 6 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Quoted 8 lines

Kernel: <bsd:bad subpartition - ignored

Though all 3 of these BSD systems use UFS as a file system, only FreeBSD uses relative start addresses in the subpartition declarations.

The following patch fixes this for FreeBSD partitions and leaves the code for OpenBSD and NetBSD intact:

I queued this up 3 days ago, and replied as such. There's no need to keep sending it.

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Richard Narron
Quoted 7 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

[]

Quoted 1 line
  block/partitions/msdos.c | 2 ++

[]

block/partitions/msdos.c static void parse_bsd(struct parsed_part · line 303

Quoted 5 lines
block/partitions/msdos.c +1 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
  			continue;
  		bsd_start = le32_to_cpu(p->p_offset);
  		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)

Weird code. Why not:

		if (strcmp(flavor, "bsd") == 0)
#3 lore raw
Quoted 19 lines · Joe Perches
Quoted 7 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

[]

Quoted 1 line
  block/partitions/msdos.c | 2 ++

[]

block/partitions/msdos.c static void parse_bsd(struct parsed_part · line 303

Quoted 5 lines
block/partitions/msdos.c +1 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
  			continue;
  		bsd_start = le32_to_cpu(p->p_offset);
  		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)

Weird code. Why not:

Quoted 2 lines
		if (strcmp(flavor, "bsd") == 0)

I instinctively trust the memcmp function as it seems more like assembly language to me and more straight forward and more reliable than strcmp.

I'm new to this forum and did not know who you were so I looked up your name in old threads and oddly enough found this thread about a strcmp bug:

http://marc.info/?l=linux-kernel&m=125848558316468&w=2

http://marc.info/?l=linux-kernel&m=125847802903422&w=2

#4 lore raw
Quoted 23 lines · Richard Narron
Quoted 21 lines · Joe Perches
Quoted 7 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

[]

Quoted 1 line
  block/partitions/msdos.c | 2 ++

[]

block/partitions/msdos.c static void parse_bsd(struct parsed_part · line 303

Quoted 5 lines
block/partitions/msdos.c +1 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
  			continue;
  		bsd_start = le32_to_cpu(p->p_offset);
  		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)

Weird code. Why not:

Quoted 6 lines
Quoted 2 lines
		if (strcmp(flavor, "bsd") == 0)

I instinctively trust the memcmp function as it seems more like assembly language to me and more straight forward and more reliable than strcmp.

That really doesn't matter.

Your code stores "bsd\0\0" and not just "bsd\0"

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

(please keep replies on the list)

Quoted 47 lines · Richard Narron
Quoted 26 lines · Joe Perches
Quoted 25 lines · Richard Narron
Quoted 23 lines · Joe Perches
Quoted 7 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

[]

Quoted 1 line
  block/partitions/msdos.c | 2 ++

[]

block/partitions/msdos.c static void parse_bsd(struct parsed_part · line 303

Quoted 5 lines
block/partitions/msdos.c +1 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
  			continue;
  		bsd_start = le32_to_cpu(p->p_offset);
  		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)

Weird code. Why not:

		if (strcmp(flavor, "bsd") == 0)
Quoted 8 lines
Quoted 3 lines

I instinctively trust the memcmp function as it seems more like assembly language to me and more straight forward and more reliable than strcmp.

That really doesn't matter.

Your code stores "bsd\0\0" and not just "bsd\0"

Thanks for looking at this code. I do appreciate it.

How about saving a byte and doing this instead?

           if (memcmp(flavour, "bsd", 4) == 0)

I do appreciate your input as coding style is important, but so too is reliability.

I don't trust the string functions and probably never will.

Quoted 8 lines

It is not surprising to me that things like SQL injection and any number of other C string exploits are very common.

IBM gave up on the idea of marking memory to keep track of data length with the 1401 machines in the 1950's.

But Digital Equipment kept the idea alive of using null characters for a long time. Sadly the C programming language copied this bad idea for strings.

Let's not argue the language.

Please use what's normal for the language as that is readers of the code typically expect.

#7 lore raw
Quoted 55 lines · Joe Perches

(please keep replies on the list)

Quoted 52 lines · Richard Narron
Quoted 26 lines · Joe Perches
Quoted 25 lines · Richard Narron
Quoted 23 lines · Joe Perches
Quoted 7 lines · Richard Narron

The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD and NetBSD partitions and does a reasonable job picking out OpenBSD and NetBSD UFS subpartitions.

But for FreeBSD the subpartitions are always "bad".

Kernel: <bsd:bad subpartition - ignored

[]

Quoted 1 line
  block/partitions/msdos.c | 2 ++

[]

block/partitions/msdos.c static void parse_bsd(struct parsed_part · line 303

Quoted 5 lines
block/partitions/msdos.c +1 -0
@@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
  			continue;
  		bsd_start = le32_to_cpu(p->p_offset);
  		bsd_size = le32_to_cpu(p->p_size);
+		if (memcmp(flavour, "bsd\0", 4) == 0)

Weird code. Why not:

		if (strcmp(flavor, "bsd") == 0)
Quoted 8 lines
Quoted 3 lines

I instinctively trust the memcmp function as it seems more like assembly language to me and more straight forward and more reliable than strcmp.

That really doesn't matter.

Your code stores "bsd\0\0" and not just "bsd\0"

Thanks for looking at this code. I do appreciate it.

How about saving a byte and doing this instead?

           if (memcmp(flavour, "bsd", 4) == 0)

I do appreciate your input as coding style is important, but so too is reliability.

I don't trust the string functions and probably never will.

It is not surprising to me that things like SQL injection and any number of other C string exploits are very common.

IBM gave up on the idea of marking memory to keep track of data length with the 1401 machines in the 1950's.

Quoted 9 lines
Quoted 3 lines

But Digital Equipment kept the idea alive of using null characters for a long time. Sadly the C programming language copied this bad idea for strings.

Let's not argue the language.

Please use what's normal for the language as that is readers of the code typically expect.

Under the /block/partitions directory the c programs have about 13 uses of memcmp() and 6 uses of strcmp().

#8 lore raw
Quoted 2 lines · Richard Narron

Under the /block/partitions directory the c programs have about 13 uses of memcmp() and 6 uses of strcmp().

Nearly all of the memcmp uses with strings kernel wide use the equivalent of memcmp(foo, "bar", strlen("bar"));