NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-amd64/59120: x86 efiboot: uninitialized/null pointer deref with efi partitions



>Number:         59120
>Category:       port-amd64
>Synopsis:       x86 efiboot: uninitialized/null pointer deref with efi partitions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-amd64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 03 14:05:00 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The NetGPT Notfoundaguid
>Environment:
>Description:
In the x86 efiboot (sys/arch/i386/stand/efiboot), a bios disk partition can have its size and fstype initialized by biosdisk.c check_gpt without also initializing its guid:

    418 			if (!guid_is_nil(u)) {
    419 				d->part[j].offset = ep[i].ent_lba_start;
    420 				d->part[j].size = ep[i].ent_lba_end -
    421 				    ep[i].ent_lba_start + 1;
    422 				if (guid_is_equal(u, &GET_nbsd_ffs))
    423 					d->part[j].fstype = FS_BSDFFS;
...
    434 				else
    435 					d->part[j].fstype = FS_OTHER;
    436 #ifndef NO_GPT
    437 				for (int k = 0;
    438 				     k < __arraycount(gpt_parts);
    439 				     k++) {
    440 					if (guid_is_equal(u, gpt_parts[k].guid))
    441 						d->part[j].guid = &gpt_parts[k];
    442 				}

https://nxr.netbsd.org/xref/src/sys/arch/i386/stand/lib/biosdisk.c?r=1.61#419

Later, efidisk_get_efi_system_partition may try to dereference the guid:

    392 		if (part[i].size == 0)
    393 			continue;
    394 		if (part[i].fstype == FS_UNUSED)
    395 			continue;
    396 		if (guid_is_equal(part[i].guid->guid, &GET_efi))
    397 			break;

https://nxr.netbsd.org/xref/src/sys/arch/i386/stand/efiboot/efidisk.c?r=1.11#392

In this case, I believe it will always be a null pointer because the whole struct biosdisk object is zeroed on allocation:

    834 void
    835 biosdisk_probe(void)
    836 {
    837 	struct biosdisk *d;
...
    852 		d = alloc(sizeof(*d));
    853 		if (d == NULL) {
    854 			printf("Out of memory\n");
    855 			return;
    856 		}
    857 		memset(d, 0, sizeof(*d));
...

(Same with biosdisk_find_name, biosdisk_find_raid, alloc_biosdisk.)

But this could be done more confidently, and the downstream dereference (whether it is currently uninitialized or null) should be protected by a null check.

[Originally reported by Vladimir `phcoder' Serbinenko: https://mail-index.netbsd.org/tech-kern/2025/03/02/msg030101.html]
>How-To-Repeat:
efiboot an x86 system on a gpt-formatted disk with a partition type not know to the bootloader, i.e., not one of the partition types listed at:

https://nxr.netbsd.org/xref/src/sys/arch/i386/stand/lib/biosdisk.c?r=1.61#160
>Fix:
1. null out d->part[j].guid up front
2. add a null test to efidisk_get_efi_system_partition



Home | Main Index | Thread Index | Old Index