wic: ensure generated disk system identifier is non-zero
PATCH v3 1/1 wic: ensure generated disk system identifier is non-zero
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/wic/plugins/imager/direct.py +1 -1
@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffff self.partitions = partitions self.partimages = []
Signature · 1 line
2.13.2
Quoted 13 lines · Jonathan Liu
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
Signed-off-by Jonathan Liu <[email protected]>--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/lib/wic/plugins/imager/direct.py +0
-0
scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 301
Quoted 6 lines
scripts/lib/wic/plugins/imager/direct.py +1
-1@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffff
Can we generate random identifier by calling os.urandom again if self.identifier is zero? Something like this, may be?
while True:
self.identifier = int.from_bytes(os.urandom(4), 'little') if self.identifier:
break
Assigning constant 0xffffffff can potentially create nonunique identifiers.
Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0
-0self.partitions = partitions self.partimages = []Signature · 7 lines
2.13.2 -- _______________________________________________ Openembedded-core mailing list [email protected] http://lists.openembedded.org/mailman/listinfo/openembedded-core
Signature · 3 lines
-- Regards, Ed
Hi Ed,
Quoted 24 lines · Ed Bartosh
Quoted 13 lines · Jonathan Liu
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
Signed-off-by Jonathan Liu <[email protected]>--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/lib/wic/plugins/imager/direct.py +0
-0scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 301
Quoted 6 lines
scripts/lib/wic/plugins/imager/direct.py +1
-1@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffffCan we generate random identifier by calling os.urandom again if self.identifier is zero? Something like this, may be?
Quoted 7 lines
while True:
self.identifier =int.from_bytes(os.urandom(4), 'little')if self.identifier:
breakAssigning constant
0xffffffffcan potentially create nonunique identifiers.
There is no guarantee that urandom will create unique identifiers. Infinite loop needs a timeout and error in the case it is unable to generate a suitable identifier. It is only 0xffffffff if it is 0. That means 0xffffffff is twice as likely to occur (2 in 4294967296 instead of 1 in 4294967296) so there is tiny bias. Note that this is how it is implemented for the DISK_SIGNATURE variable in OE and in GNU Parted as well.
Quoted 11 lines
Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0
-1self.partitions = partitions self.partimages = [] --2.13.2
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Quoted 4 lines
--
--
Regards,
Ed
Regards,
Jonathan
Quoted 32 lines · Jonathan Liu
Hi Ed,
Quoted 29 lines · Ed Bartosh
Quoted 13 lines · Jonathan Liu
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
Signed-off-by Jonathan Liu <[email protected]>--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/lib/wic/plugins/imager/direct.py +0
-0scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 301
Quoted 6 lines
scripts/lib/wic/plugins/imager/direct.py +1
-1@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffffCan we generate random identifier by calling os.urandom again if self.identifier is zero? Something like this, may be?
while True:
self.identifier =int.from_bytes(os.urandom(4), 'little')if self.identifier:
break
Quoted 4 lines
Quoted 2 lines
Assigning constant
0xffffffffcan potentially create nonunique identifiers.There is no guarantee that urandom will create unique identifiers.
We can't have a guarantee with urandom, true. My point was that if you need random value it's better to call urandom again than using a constant value.
Quoted 2 lines
Infinite loop needs a timeout and error in the case it is unable to generate a suitable identifier.
I'm not sure it's needed, but it's not a big deal to add this. I really doubt os.urandom can generate long enough sequence of zeros.
Quoted 5 lines
It is only
0xffffffffif it is 0. That
means0xffffffffis twice as likely to occur (2 in 4294967296 instead of 1 in 4294967296) so there is tiny bias. Note that this is how it is implemented for theDISK_SIGNATUREvariable in OE and in GNU Parted as well.
Does this mean we shouldn't do better?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
scripts/lib/wic/plugins/imager/direct.py +0
-1self.partitions = partitions self.partimages = [] --2.13.2
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-coreRegards,
Jonathan
--
Regards,
Ed
Hi Ed,
Quoted 45 lines · Ed Bartosh
Quoted 32 lines · Jonathan Liu
Hi Ed,
Quoted 29 lines · Ed Bartosh
Quoted 13 lines · Jonathan Liu
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
Signed-off-by Jonathan Liu <[email protected]>--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/lib/wic/plugins/imager/direct.py +0
-0scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 301
Quoted 6 lines
scripts/lib/wic/plugins/imager/direct.py +1
-1@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffffCan we generate random identifier by calling os.urandom again if self.identifier is zero? Something like this, may be?
while True:
self.identifier =int.from_bytes(os.urandom(4), 'little')if self.identifier:
breakQuoted 4 lines
Quoted 2 lines
Assigning constant
0xffffffffcan potentially create nonunique identifiers.There is no guarantee that urandom will create unique identifiers.
We can't have a guarantee with urandom, true. My point was that if you need random value it's better to call urandom again than using a constant value.
Quoted 2 lines
Infinite loop needs a timeout and error in the case it is unable to generate a suitable identifier.
I'm not sure it's needed, but it's not a big deal to add this. I really doubt os.urandom can generate long enough sequence of zeros.
Quoted 7 lines
Quoted 5 lines
It is only
0xffffffffif it is 0. That
means0xffffffffis twice as likely to occur (2 in 4294967296 instead of 1 in 4294967296) so there is tiny bias. Note that this is how it is implemented for theDISK_SIGNATUREvariable in OE and in GNU Parted as well.Does this mean we shouldn't do better?
How about random.SystemRandom().randrange(1, 0xffffffff) ?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0
-1self.partitions = partitions self.partimages = [] --2.13.2
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Quoted 6 lines
Quoted 2 lines
Regards,
Jonathan--
Regards,
Ed
Regards,
Jonathan
Quoted 53 lines · Jonathan Liu
Hi Ed,
Quoted 50 lines · Ed Bartosh
Quoted 32 lines · Jonathan Liu
Hi Ed,
Quoted 29 lines · Ed Bartosh
Quoted 13 lines · Jonathan Liu
Zero may be interpreted as no MBR signature present and another partitioning program might install a new MBR signature.
Signed-off-by Jonathan Liu <[email protected]>--- scripts/lib/wic/plugins/imager/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/lib/wic/plugins/imager/direct.py +0
-0scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 301
Quoted 6 lines
scripts/lib/wic/plugins/imager/direct.py +1
-1@@ -297,7 +297,7 @@ class PartitionedImage(): # all partitions (in bytes) self.ptable_format = ptable_format # Partition table format # Disk system identifier - self.identifier = int.from_bytes(os.urandom(4), 'little') + self.identifier = int.from_bytes(os.urandom(4), 'little') or 0xffffffffCan we generate random identifier by calling os.urandom again if self.identifier is zero? Something like this, may be?
while True:
self.identifier =int.from_bytes(os.urandom(4), 'little')if self.identifier:
breakQuoted 4 lines
Quoted 2 lines
Assigning constant
0xffffffffcan potentially create nonunique identifiers.There is no guarantee that urandom will create unique identifiers.
We can't have a guarantee with urandom, true. My point was that if you need random value it's better to call urandom again than using a constant value.
Quoted 2 lines
Infinite loop needs a timeout and error in the case it is unable to generate a suitable identifier.
I'm not sure it's needed, but it's not a big deal to add this. I really doubt os.urandom can generate long enough sequence of zeros.
Quoted 5 lines
It is only
0xffffffffif it is 0. That
means0xffffffffis twice as likely to occur (2 in 4294967296 instead of 1 in 4294967296) so there is tiny bias. Note that this is how it is implemented for theDISK_SIGNATUREvariable in OE and in GNU Parted as well.
Quoted 5 lines
Quoted 2 lines
Does this mean we shouldn't do better?
How about random.SystemRandom().randrange(1,
0xffffffff) ?
random.SystemRandom().randint(1, 0xffffffff) actually
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
scripts/lib/wic/plugins/imager/direct.py +0
-1self.partitions = partitions self.partimages = [] --2.13.2
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-coreQuoted 6 lines
Quoted 2 lines
Regards,
Jonathan--
Regards,
EdRegards,
Jonathan
Quoted 6 lines · Jonathan Liu
Quoted 3 lines
How about random.SystemRandom().randrange(1,
0xffffffff) ?random.SystemRandom().randint(1,
0xffffffff) actually
This looks ok to me. Thanks.
--
Regards,
Ed