Commit Graph

41 Commits

Author SHA1 Message Date
Peter Jones f725fa7cb2 calloc: Use calloc() at most places
This modifies most of the places we do some form of:

  X = malloc(Y * Z);

to use calloc(Y, Z) instead.

Among other issues, this fixes:
  - allocation of integer overflow in grub_png_decode_image_header()
    reported by Chris Coulson,
  - allocation of integer overflow in luks_recover_key()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_lvm_detect()
    reported by Chris Coulson.

Fixes: CVE-2020-14308

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-07-29 16:55:47 +02:00
Vladimir Serbinenko 384091967d Rename grub_disk members
Otherwise it horribly clashes with gnulib when it's
replacing open/write/read/close

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
2019-03-25 15:14:52 +01:00
Eric Snowberg 3434ddec0e ieee1275: obdisk driver
Add a new disk driver called obdisk for IEEE1275 platforms.  Currently
the only platform using this disk driver is SPARC, however other IEEE1275
platforms could start using it if they so choose.  While the functionality
within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it
presented too many problems on SPARC hardware.

Within the old ofdisk, there is not a way to determine the true canonical
name for the disk.  Within Open Boot, the same disk can have multiple names
but all reference the same disk.  For example the same disk can be referenced
by its SAS WWN, using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0

It can also be referenced by its PHY identifier using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0

It can also be referenced by its Target identifier using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0

Also, when the LUN=0, it is legal to omit the ,0 from the device name.  So with
the disk above, before taking into account the device aliases, there are 6 ways
to reference the same disk.

Then it is possible to have 0 .. n device aliases all representing the same disk.
Within this new driver the true canonical name is determined using the the
IEEE1275 encode-unit and decode-unit commands when address_cells == 4.  This
will determine the true single canonical name for the device so multiple ihandles
are not opened for the same device.  This is what frequently happens with the old
ofdisk driver.  With some devices when they are opened multiple times it causes
the entire system to hang.

Another problem solved with this driver is devices that do not have a device
alias can be booted and used within GRUB. Within the old ofdisk, this was not
possible, unless it was the original boot device.  All devices behind a SAS
or SCSI parent can be found.   Within the old ofdisk, finding these disks
relied on there being an alias defined.  The alias requirement is not
necessary with this new driver.  It can also find devices behind a parent
after they have been hot-plugged.  This is something that is not possible
with the old ofdisk driver.

The old ofdisk driver also incorrectly assumes that the device pointing to by a
device alias is in its true canonical form. This assumption is never made with
this new driver.

Another issue solved with this driver is that it properly caches the ihandle
for all open devices.  The old ofdisk tries to do this by caching the last
opened ihandle.  However this does not work properly because the layer above
does not use a consistent device name for the same disk when calling into the
driver.  This is because the upper layer uses the bootpath value returned within
/chosen, other times it uses the device alias, and other times it uses the
value within grub.cfg.  It does not have a way to figure out that these devices
are the same disk.  This is not a problem with this new driver.

Due to the way GRUB repeatedly opens and closes the same disk. Caching the
ihandle is important on SPARC.  Without caching, some SAS devices can take
15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible
without correctly having the canonical disk name.

When available, this driver also tries to use the deblocker #blocks and
a way of determining the disk size.

Finally and probably most importantly, this new driver is also capable of
seeing all partitions on a GPT disk.  With the old driver, the GPT
partition table can not be read and only the first partition on the disk
can be seen.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-12 20:04:07 +01:00
Paulo Flabiano Smorigo c899d9f42c ofdisk: add sas disks to the device list 2015-11-12 09:23:02 -02:00
Paulo Flabiano Smorigo a50dbb743e ofdisk: add a comment about vscsi method 2015-11-10 21:20:20 -02:00
Eric Snowberg 0b72543afd ofdisk: Fix devpath freeing logic. 2015-10-26 23:03:06 +01:00
Vladimir Serbinenko 87ec3b7fa9 Don't continue to query block-size if disk doesn't have it.
Stops poluting screen with a lot of "block-size: exception -21".
2015-03-03 20:50:37 +01:00
Vladimir Serbinenko 967e5aa591 ofdisk: Exclude floppies from scanning.
It causes similar hang as CD on at least the qemu.
2015-02-21 16:16:48 +01:00
Vladimir Serbinenko f1959b1695 * grub-core/disk/ieee1275/nand.c (grub_nand_open): Check block size
validity.
2015-01-21 17:42:11 +01:00
Vladimir Serbinenko 234d93464a * grub-core/disk/ieee1275/ofdisk.c: Remove variable length arrays.
* grub-core/net/drivers/ieee1275/ofnet.c: Likewise.
2013-12-04 08:10:01 +01:00
Vladimir 'phcoder' Serbinenko e2f27a8c53 Enforce disabling of firmware disk drivers when native drivers kick in. 2013-04-29 12:16:46 +02:00
Vladimir 'phcoder' Serbinenko 21aecce0f9 * grub-core/disk/ieee1275/ofdisk.c: Fix CD-ROM and boot device
detection.
2013-04-15 00:38:39 +02:00
Vladimir 'phcoder' Serbinenko ac4fea7998 * grub-core/disk/ieee1275/ofdisk.c: Iterate over bootpath even if it
would be otherwise excluded.
2013-04-14 16:55:20 +02:00
Vladimir 'phcoder' Serbinenko e42b251403 * grub-core/disk/ieee1275/nand.c: Fix compilation on
i386-ieee1275.
2013-03-03 01:30:55 +01:00
Vladimir 'phcoder' Serbinenko 6e4146c41e Move to more hookless approach in IEEE1275 devices handling. 2013-03-02 23:51:19 +01:00
Vladimir 'phcoder' Serbinenko b5ea6ce03a Support Openfirmware disks with non-512B sectors.
* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
	size of the disk.
	* (grub_ofdisk_get_block_size): New function.
	* (grub_ofdisk_prepare): Use the correct block size.
	* (grub_ofdisk_read): Likewise.
	* (grub_ofdisk_write): Likewise.
	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size):
	New proto.
2013-02-19 09:10:26 +01:00
Colin Watson 25239370fd Remove nested functions from device iterators.
* include/grub/arc/arc.h (grub_arc_iterate_devs_hook_t): New type.
(grub_arc_iterate_devs): Add hook_data argument.
* include/grub/ata.h (grub_ata_dev_iterate_hook_t): New type.
(struct grub_ata_dev.iterate): Add hook_data argument.
* include/grub/device.h (grub_device_iterate_hook_t): New type.
(grub_device_iterate): Add hook_data argument.
* include/grub/disk.h (grub_disk_dev_iterate_hook_t): New type.
(struct grub_disk_dev.iterate): Add hook_data argument.
(grub_disk_dev_iterate): Likewise.
* include/grub/gpt_partition.h (grub_gpt_partition_map_iterate):
Likewise.
* include/grub/msdos_partition.h (grub_partition_msdos_iterate):
Likewise.
* include/grub/partition.h (grub_partition_iterate_hook_t): New
type.
(struct grub_partition_map.iterate): Add hook_data argument.
(grub_partition_iterate): Likewise.
* include/grub/scsi.h (grub_scsi_dev_iterate_hook_t): New type.
(struct grub_scsi_dev.iterate): Add hook_data argument.

Update all callers.
2013-01-20 15:52:15 +00:00
Vladimir 'phcoder' Serbinenko 10ca8645cc * grub-core/disk/diskfilter.c (grub_diskfilter_write): Call
grub_error properly.
	* grub-core/disk/ieee1275/nand.c (grub_nand_write): Likewise.
	* grub-core/disk/loopback.c (grub_loopback_write): Likewise.
2013-01-05 15:10:46 +01:00
Vladimir 'phcoder' Serbinenko 64498f2538 * grub-core/disk/ieee1275/ofdisk.c (scan): Check function return value.
* grub-core/lib/ieee1275/datetime.c (grub_get_datetime): Likewise.
	(grub_set_datetime): Likewise.
2012-09-05 08:56:08 +02:00
Vladimir 'phcoder' Serbinenko 538478d082 * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Fix double
increment.
2012-06-21 21:59:52 +02:00
Vladimir 'phcoder' Serbinenko 436575581e * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Escape commas. 2012-06-20 23:37:24 +02:00
Vladimir 'phcoder' Serbinenko 4abde34671 Revert usb-quiesce since it's wrong.
* grub-core/disk/ieee1275/ofdisk.c (quiesce): Removed.
	(grub_ofdisk_init): Don't do quiesce.
2012-06-13 22:44:45 +02:00
Vladimir 'phcoder' Serbinenko 7bc06a4995 * grub-core/disk/ieee1275/ofdisk.c (quiesce): New function.
(grub_ofdisk_fini): Quiesce USB devices.
2012-06-06 19:00:04 +02:00
Vladimir 'phcoder' Serbinenko bf293dece0 * grub-core/disk/ieee1275/ofdisk.c (scan): Support vscsi on IBM
machines.
	Tested by: Paulo Flabiano Smorigo.
	Crucial information about API supplied by: Coleen <Last name unknown>.
	Reviewed by: Coleen <Last name unknown>.
2012-06-06 02:31:27 +02:00
Vladimir 'phcoder' Serbinenko 5560e9d6e1 * grub-core/disk/ieee1275/ofdisk.c (scan): Don't scan device tree if
GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS is set.
	* grub-core/kern/ieee1275/cmain.c (grub_ieee1275_find_options): Set
	GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS on IBM hardware.
	* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New enum value
	GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS.
2012-05-13 20:29:23 +02:00
Vladimir 'phcoder' Serbinenko d5534665ff Make nand a prefix for nand devices.
* grub-core/disk/ieee1275/nand.c (grub_nand_open): Use prefix nand.
2012-02-26 23:59:00 +01:00
Vladimir 'phcoder' Serbinenko 0ec820904e * grub-core/disk/ieee1275/ofdisk.c (scan): Fix improper use of device
name as if it was an alias.
2012-02-26 16:51:25 +01:00
Vladimir 'phcoder' Serbinenko d61386e21d Improve string. Gettextize. 2012-02-12 15:25:25 +01:00
Vladimir 'phcoder' Serbinenko 9c4b5c13e6 Improve gettext support. Stylistic fixes and error handling fixes while
on it.
2012-02-08 19:26:01 +01:00
Vladimir 'phcoder' Serbinenko 7626111087 IEEE1275 disk write support.
* grub-core/kern/ieee1275/ieee1275.c (grub_ieee1275_write): Make buffer
	const void *.
	* include/grub/ieee1275/ieee1275.h (grub_ieee1275_write): Likewise.
	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_read): Move open
	and seek loginc to ...
	(grub_ofdisk_prepare): ... here.
	(grub_ofdisk_write): Implement.
2012-01-25 18:32:08 +01:00
Vladimir 'phcoder' Serbinenko 9197b0ade5 * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Add ieee1275/
prefix.
	(grub_ofdisk_open): Check and discard ieee1275 prefix.
	* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname):
	Add ieee1275 prefix.
2011-12-24 02:40:18 +01:00
Vladimir 'phcoder' Serbinenko ca74c50c0b merge mainline into hints 2011-12-23 18:46:06 +01:00
Vladimir 'phcoder' Serbinenko 0044d1db2e Simplify disk opening 2011-07-07 21:46:25 +02:00
Vladimir 'phcoder' Serbinenko 00542307eb merge mainline into lazy 2011-07-07 12:21:53 +02:00
Vladimir 'phcoder' Serbinenko c97dbbf2f2 Fix a memory leak 2011-07-06 17:40:24 +02:00
Vladimir 'phcoder' Serbinenko e745cf0ca6 Implement automatic module license checking according to new GNU
guidelines.

	* grub-core/kern/dl.c (grub_dl_check_license): New function.
	(grub_dl_load_core): Use grub_dl_check_license.
	* include/grub/dl.h (GRUB_MOD_SECTION): New macro.
	(GRUB_MOD_LICENSE): Likewise.
	(GRUB_MOD_DUAL_LICENSE): Likewise.
	All modules updated.
2011-04-11 23:01:51 +02:00
Vladimir 'phcoder' Serbinenko b44a558c9a Use alias->path rather than buggy "canon".
* grub-core/disk/ieee1275/ofdisk.c (ofdisk_hash_add_real): New function.
	(ofdisk_hash_add): New argument curcan. All users updated.
2011-01-12 11:26:28 +01:00
Vladimir 'phcoder' Serbinenko 94564f81a8 * include/grub/disk.h (grub_disk): Remove has_partitions.
All users updated.
	* disk/loopback.c (grub_loopback): Remove has_partitions.
	All users updated.
	(options): Remove partitions. All users updated.
	* util/grub-fstest.c (fstest): Don't pass "-p" to loopback.
	* util/i386/pc/grub-setup.c (setup): copy partition table only when
	actual partition table is found.
2010-09-13 23:59:22 +02:00
Vladimir 'phcoder' Serbinenko b2a30ac5e4 Filter devaliases and never open same device twice.
* grub-core/disk/ieee1275/ofdisk.c (last_devpath): New variable.
	(last_ihandle): Likewise.
	(ofdisk_hash_ent): New member shortest.
	(ofdisk_hash_add): Add canonical path too.
	(scan): New function.
	(grub_ofdisk_iterate): Iterate over hashed entries.
	(compute_dev_path): Don't add :0.
	(grub_ofdisk_open): Don't really open the disk.
	(grub_ofdisk_close): Avoid closing unrelated disk.
	(grub_ofdisk_read): Implement reopen logic.
	* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_canonicalise_devname):
	New function.
	* include/grub/ieee1275/ieee1275.h (grub_ieee1275_canonicalise_devname):
	New proto.
2010-09-13 19:17:29 +02:00
BVK Chaitanya a762e3c335 merge with mainline 2010-06-01 17:52:31 +05:30
BVK Chaitanya 8c41176882 automake commit without merge history 2010-05-06 11:34:04 +05:30