Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2185564

Summary: [RHEL9] get Segmentation fault failed when add partition
Product: Red Hat Enterprise Linux 9 Reporter: guazhang <guazhang>
Component: libblockdevAssignee: Vojtech Trefny <vtrefny>
Status: CLOSED ERRATA QA Contact: guazhang <guazhang>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.2CC: bcl, vtrefny
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libblockdev-2.28-6.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2207500 (view as bug list) Environment:
Last Closed: 2023-11-07 08:25:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description guazhang@redhat.com 2023-04-10 09:26:20 UTC
Description of problem:
libblockdev regression testing found Segmentation fault (core dumped) error when add a partition

Version-Release number of selected component (if applicable):
libblockdev-2.28-5.el9.x86_64
libblockdev-part-2.28-5.el9.x86_64
5.14.0-295.el9.x86_64

How reproducible:


Steps to Reproduce:
1. gitlab.cee.redhat.com/kernel-qe/kernel/-/archive/master/kernel-master.tar.gz/storage/dm-crypt/cryptsetup_libblockdev
2.
3.

Actual results:


Expected results:


Additional info:


pr 10 05:16:54 storageqe-105 kernel: python3[3782]: segfault at 18 ip 00007f7ce0a1cb94 sp 00007ffe4b4b9658 error 4 in libparted.so.2.0.4[7f7ce0a12000+3e000] likely on CPU 2 (core 1, socket 0)
Apr 10 05:16:54 storageqe-105 kernel: Code: 29 c2 4c 89 c6 4c 89 cf 48 83 c2 01 e9 85 71 ff ff 0f 1f 44 00 00 31 c0 c3 66 66 2e 0f 1f 84 00 00 00 00 00 66 90 f3 0f 1e fa <48> 8b 57 18 48 29 f2 48 83 c2 01 e9 1c 7a ff ff 66 66 2e 0f 1f 84
Apr 10 05:16:54 storageqe-105 systemd[1]: Created slice Slice /system/systemd-coredump.
Apr 10 05:16:54 storageqe-105 systemd[1]: Started Process Core Dump (PID 3879/UID 0).
Apr 10 05:16:54 storageqe-105 systemd-coredump[3883]: Resource limits disable core dumping for process 3782 (python3).
Apr 10 05:16:54 storageqe-105 systemd-coredump[3883]: Process 3782 (python3) of user 0 dumped core.
Apr 10 05:16:54 storageqe-105 systemd[1]: systemd-coredump: Deactivated successfully.
Apr 10 05:17:01 storageqe-105 NetworkManager[966]: <warn>  [1681118221.2506] platform-linux: do-add-ip



looks just hit the error with big disks, 

sda                            8:0    0   7.3T  0 disk 
sdb                            8:16   0   7.3T  0 disk 
sdc                            8:32   0   7.3T  0 disk 
sdd                            8:48   0   7.3T  0 disk 
sde                            8:64   0   7.3T  0 disk 
sdf                            8:80   0   7.3T  0 disk 
sdg                            8:96   0 558.4G  0 disk 


[root@storageqe-105 cryptsetup_libblockdev]# python3 
Python 3.9.16 (main, Dec  8 2022, 00:00:00) 
[GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import luks as l
>>> o=l.Luks()
INFO: Service stratisd is running.
>>> o.add_part('/dev/sdc')
[2023-04-10 05:16:54]  INFO: will add a part table 
Segmentation fault (core dumped)

Comment 1 Vojtech Trefny 2023-04-14 12:39:30 UTC
Moving to parted for further investigation. Having a full backtrace would be better to tell where exactly the problem is, but this is most likely caused by using MSDOS partition table[1] which is limited to 2 TiB and sdc here is 7.3 TiB. Maybe we should check this in libblockdev before trying to create the partition table and return an error, but I think this shouldn't cause a segfault in libparted.

[1] https://gitlab.cee.redhat.com/kernel-qe/kernel/-/blob/master/storage/dm-crypt/cryptsetup_libblockdev/luks.py#L722

Comment 2 Brian Lane 2023-04-14 18:33:46 UTC
Yeah, I need more info. Can you reproduce this on the cmdline for example? Or get a traceback with the debuginfo package installed so it tells more about exactly where it crashed. Also, libparted has a pile of internal checks for unexpected situations, so it is possible for it to trigger an assert() if it is given bad data by the caller.

Comment 3 guazhang@redhat.com 2023-04-17 00:21:34 UTC
Hi,
update MSDOS to GPT that works well.

bd.part.create_table(disk, bd.PartTableType.GPT, False)

>>> o.add_part('/dev/sda')
[2023-04-16 20:14:12]  INFO: will add a part table 
[2023-04-16 20:14:12]  INFO: have create /dev/sda1 
'/dev/sda1'

the cmd fdisk/parted add a partition successful.
parted -s  /dev/sdb   mkpart primary 513M  12288M

Comment 4 Brian Lane 2023-04-17 17:15:04 UTC
Is 12288M the same end it is trying to make with o.add_part? I tried to cause errors using a 8TiB qcow2 image and pyparted, and no matter what I did it properly raised an exception when trying to make partitions larger than what msdos supports. So without an actual traceback or reproducer there isn't much I can do to debug this. It's possible that whatever you are doing is feeding wrong sizes to libparted, but you should be getting an exception, not a coredump.

Comment 5 guazhang@redhat.com 2023-04-18 09:24:43 UTC
HI,

[root@storageqe-105 ~]# lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0   7.3T  0 disk 
└─sda1                         8:1    0     5G  0 part 
sdb                            8:16   0   7.3T  0 disk 
sdc                            8:32   0   7.3T  0 disk 
sdd                            8:48   0   7.3T  0 disk 
sde                            8:64   0   7.3T  0 disk 
sdf                            8:80   0   7.3T  0 disk 
sdg                            8:96   0 558.4G  0 disk 
├─sdg1                         8:97   0     1G  0 part /boot
└─sdg2                         8:98   0 557.4G  0 part 
  ├─rhel_storageqe--105-root 253:0    0    70G  0 lvm  /
  ├─rhel_storageqe--105-swap 253:1    0   7.6G  0 lvm  [SWAP]
  └─rhel_storageqe--105-home 253:2    0 479.7G  0 lvm  /home
sdh                            8:112  0   7.3T  0 disk 
sr0                           11:0    1  1024M  0 rom  



```
    def add_part(self, disk, size=5):
        if not isinstance(size,int):
            self._print("FAIL: input wrong size type, please input int type, default is G")
            return
        self.init_disk(disk)
        self._print("INFO: will add a part table")
        bd.part.create_table(disk, bd.PartTableType.MSDOS, False)
        ps=bd.part.create_part(disk, bd.PartTypeReq.NORMAL, 2048*512, int(size) * 1024**3, bd.PartAlign.OPTIMAL )
        if not ps.path :
            self._print("FAIL: can not get part")
            return
        self._print("INFO: have create %s" % ps.path)
        return ps.path

```

the add_part will add 5G partition as default.


[root@storageqe-105 cryptsetup_libblockdev]# parted /dev/sdb
GNU Parted 3.5
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]?                                                
Start? 0                                                                  
End? 5G                                                                   
Warning: The resulting partition is not properly aligned for best performance: 1s % 2048s != 0s
Ignore/Cancel? Ignore                                                     
(parted) print                                                            
Model: ATA ST8000NM000A-2KE (scsi)
Disk /dev/sdb: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags: 

Number  Start  End     Size    Type     File system  Flags
 1      512B   5000MB  5000MB  primary  ext2

(parted) quit
Information: You may need to update /etc/fstab.

[root@storageqe-105 cryptsetup_libblockdev]# lsblk                        
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0   7.3T  0 disk 
└─sda1                         8:1    0     5G  0 part 
sdb                            8:16   0   7.3T  0 disk 
└─sdb1                         8:17   0   4.7G  0 part 
sdc                            8:32   0   7.3T  0 disk 
sdd                            8:48   0   7.3T  0 disk 
sde                            8:64   0   7.3T  0 disk 
sdf                            8:80   0   7.3T  0 disk 
sdg                            8:96   0 558.4G  0 disk 
├─sdg1                         8:97   0     1G  0 part /boot
└─sdg2                         8:98   0 557.4G  0 part 
  ├─rhel_storageqe--105-root 253:0    0    70G  0 lvm  /
  ├─rhel_storageqe--105-swap 253:1    0   7.6G  0 lvm  [SWAP]
  └─rhel_storageqe--105-home 253:2    0 479.7G  0 lvm  /home
sdh                            8:112  0   7.3T  0 disk 
sr0                           11:0    1  1024M  0 rom  
[root@storageqe-105 cryptsetup_libblockdev]# 
[root@storageqe-105 cryptsetup_libblockdev]# lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0   7.3T  0 disk 
└─sda1                         8:1    0     5G  0 part 
sdb                            8:16   0   7.3T  0 disk 
sdc                            8:32   0   7.3T  0 disk 
sdd                            8:48   0   7.3T  0 disk 
sde                            8:64   0   7.3T  0 disk 
sdf                            8:80   0   7.3T  0 disk 
sdg                            8:96   0 558.4G  0 disk 
├─sdg1                         8:97   0     1G  0 part /boot
└─sdg2                         8:98   0 557.4G  0 part 
  ├─rhel_storageqe--105-root 253:0    0    70G  0 lvm  /
  ├─rhel_storageqe--105-swap 253:1    0   7.6G  0 lvm  [SWAP]
  └─rhel_storageqe--105-home 253:2    0 479.7G  0 lvm  /home
sdh                            8:112  0   7.3T  0 disk 
sr0                           11:0    1  1024M  0 rom  
[root@storageqe-105 cryptsetup_libblockdev]# parted -s  /dev/sdb   mkpart primary 0 5G
Warning: The resulting partition is not properly aligned for best performance: 1s % 2048s != 0s
[root@storageqe-105 cryptsetup_libblockdev]# lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0   7.3T  0 disk 
└─sda1                         8:1    0     5G  0 part 
sdb                            8:16   0   7.3T  0 disk 
└─sdb1                         8:17   0   4.7G  0 part 
sdc                            8:32   0   7.3T  0 disk 
sdd                            8:48   0   7.3T  0 disk 
sde                            8:64   0   7.3T  0 disk 
sdf                            8:80   0   7.3T  0 disk 
sdg                            8:96   0 558.4G  0 disk 
├─sdg1                         8:97   0     1G  0 part /boot
└─sdg2                         8:98   0 557.4G  0 part 
  ├─rhel_storageqe--105-root 253:0    0    70G  0 lvm  /
  ├─rhel_storageqe--105-swap 253:1    0   7.6G  0 lvm  [SWAP]
  └─rhel_storageqe--105-home 253:2    0 479.7G  0 lvm  /home
sdh                            8:112  0   7.3T  0 disk 
sr0                           11:0    1  1024M  0 rom  
[root@storageqe-105 cryptsetup_libblockdev]#

Comment 7 Brian Lane 2023-04-18 16:49:17 UTC
I installed the parted and libbd_part debug files, gdb, and turned on coredump in order to debug this.
What's happening is libbd_part is passing a null pointer into libparted:

#0  ped_geometry_set_start (geom=0x0, start=2048) at cs/geom.c:183
183             return ped_geometry_set (geom, start, geom->end - start + 1);

The libbd_part code calling it looks like this:

843         geom = ped_disk_get_max_partition_geometry (disk, part, constr);
844         if (!ped_geometry_set_start (geom, start)) {

libbd_part is not checking geom for NULL before passing it to ped_geometry_set_start, which assumes geom is valid, tries to get the geom->end value and crashes.

Comment 8 Vojtech Trefny 2023-04-20 09:19:17 UTC
Thank you for the help, I posted a fix upstream.

Comment 10 guazhang@redhat.com 2023-05-18 00:49:33 UTC
Hi,

I test the fixed package but looks get the error, is it expected ?
libblockdev-2.28-6.el9.x86_64

>>> o.add_part('/dev/sdb')
[2023-05-17 20:44:59]  INFO: will add a part table 
Traceback (most recent call last):
  File "/usr/lib64/python3.9/site-packages/gi/overrides/BlockDev.py", line 1093, in wrapped
    ret = orig_obj(*args, **kwargs)
gi.repository.GLib.GError: g-bd-part-error-quark: Failed to create geometry for partition on device '/dev/sdb' (partition length of 15628050432 sectors exceeds the msdos-partition-table-imposed maximum of 4294967295) (2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kernel-master/storage/dm-crypt/cryptsetup_libblockdev/luks.py", line 730, in add_part
    ps=bd.part.create_part(disk, bd.PartTypeReq.NORMAL, 2048*512, int(size) * 1024**3, bd.PartAlign.OPTIMAL )
  File "/usr/lib64/python3.9/site-packages/gi/overrides/BlockDev.py", line 1115, in wrapped
    raise transform[1](msg)
gi.overrides.BlockDev.PartError: Failed to create geometry for partition on device '/dev/sdb' (partition length of 15628050432 sectors exceeds the msdos-partition-table-imposed maximum of 4294967295)
>>>

Comment 11 Vojtech Trefny 2023-05-18 06:38:57 UTC
Yes, this is expected. The msdos partition table is limited to 2 TiB, it can be created on a bigger device but you won't then be able to create a partition exceeding the 2 TiB limit which is what the error says (15628050432 sectors is approximately 7.3 TiB).

Comment 15 errata-xmlrpc 2023-11-07 08:25:07 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libblockdev bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:6342