Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

2024-05-18 Thread Vladimir 'phcoder' Serbinenko
Le ven. 17 mai 2024, 21:26, Gao Xiang  a
écrit :

> Hi Vladimir,
>
> On 2024/5/18 00:38, Vladimir 'phcoder' Serbinenko wrote:
> > I think that given that align is a non zero const we can trust it.
>
>  From the EROFS specific cases, they are always non-zero values,
> So I agree with you on this..
>
> Yet Daniel said ".. Be careful with underflows too." in
> https://lore.kernel.org/r/zkcv7g7mjbg8s...@tomti.i.net-space.pl
> although I'm not quite sure but I guess like this.
>
> Also as a generic helper, I think `align` could be zero if it's
> a variable..
>

It's rare for align to be a variable and then additional checks are needed
that align is a power of 2. And power of 2 is never zero. This check is
better done on the caller side. You just need a comment specify that it's
caller responsibility to check it.

>
> Anyway, either way works for EROFS.   I just try my best to do
> what I could do for this first series for upstreaming and we
> could move forward to the next step..
>
> Thanks,
> Gao Xiang
>
> >
> > Le ven. 17 mai 2024, 15:56, Gao Xiang  <mailto:hsiang...@linux.alibaba.com>> a écrit :
> >
> > The following EROFS patch will use this helper to handle overflow
> > ALIGN_UP() cases.
> >
> > Signed-off-by: Gao Xiang  hsiang...@linux.alibaba.com>>
> > ---
> >   include/grub/safemath.h | 16 
> >   1 file changed, 16 insertions(+)
> >
> > diff --git a/include/grub/safemath.h b/include/grub/safemath.h
> > index fbd9b5925..baaea0ef4 100644
> > --- a/include/grub/safemath.h
> > +++ b/include/grub/safemath.h
> > @@ -32,6 +32,22 @@
> >
> >   #define grub_cast(a, res)  grub_add ((a), 0, (res))
> >
> > +#define ALIGN_UP_OVF(v, align, res)\
> > +({ \
> > +  bool __failed;   \
> > +  typeof(v) a; \
> > +   \
> > +  __failed = grub_sub ((typeof(v))(align), 1, ); \
> > +  if (__failed == false)   \
> > +{  \
> > +__failed = grub_add (v, a, res);   \
> > +if (__failed == false) \
> > +  {\
> > +*(res) &= ~a;  \
> > +  }\
> > +}  \
> > +__failed;})
> > +
> >   #else
> >   #error gcc 5.1 or newer or clang 8.0 or newer is required
> >   #endif
> > --
> > 2.39.3
> >
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

2024-05-17 Thread Vladimir 'phcoder' Serbinenko
I think that given that align is a non zero const we can trust it.

Le ven. 17 mai 2024, 15:56, Gao Xiang  a
écrit :

> The following EROFS patch will use this helper to handle overflow
> ALIGN_UP() cases.
>
> Signed-off-by: Gao Xiang 
> ---
>  include/grub/safemath.h | 16 
>  1 file changed, 16 insertions(+)
>
> diff --git a/include/grub/safemath.h b/include/grub/safemath.h
> index fbd9b5925..baaea0ef4 100644
> --- a/include/grub/safemath.h
> +++ b/include/grub/safemath.h
> @@ -32,6 +32,22 @@
>
>  #define grub_cast(a, res)  grub_add ((a), 0, (res))
>
> +#define ALIGN_UP_OVF(v, align, res)\
> +({ \
> +  bool __failed;   \
> +  typeof(v) a; \
> +   \
> +  __failed = grub_sub ((typeof(v))(align), 1, ); \
> +  if (__failed == false)   \
> +{  \
> +__failed = grub_add (v, a, res);   \
> +if (__failed == false) \
> +  {\
> +*(res) &= ~a;  \
> +  }\
> +}  \
> +__failed;})
> +
>  #else
>  #error gcc 5.1 or newer or clang 8.0 or newer is required
>  #endif
> --
> 2.39.3
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 3/3] keccak: Disable acceleration with SSE asm

2024-05-17 Thread Vladimir 'phcoder' Serbinenko
Le ven. 17 mai 2024, 14:15, Daniel Kiper  a écrit :

> Why is this patch needed? Should not we disable SSE using compiler flags?
>
We do but the code in question uses SSE on every x64 platform. So we need
to disable this acceleration. At least for now. If we want to enable SSE
(maybe we should) we can revisit this but this is a separate discussion and
separate patchset

>
> Daniel
>
> On Thu, May 16, 2024 at 09:27:43PM +0300, Vladimir Serbinenko wrote:
> > ---
> >  grub-core/lib/libgcrypt/cipher/keccak.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/grub-core/lib/libgcrypt/cipher/keccak.c
> b/grub-core/lib/libgcrypt/cipher/keccak.c
> > index 11e64b3e7..8b570263b 100644
> > --- a/grub-core/lib/libgcrypt/cipher/keccak.c
> > +++ b/grub-core/lib/libgcrypt/cipher/keccak.c
> > @@ -251,7 +251,7 @@ keccak_absorb_lane32bi(u32 *lane, u32 x0, u32 x1)
> >  /* Construct generic 64-bit implementation. */
> >  #ifdef USE_64BIT
> >
> > -#if __GNUC__ >= 4 && defined(__x86_64__)
> > +#if __GNUC__ >= 4 && defined(__x86_64__) && 0
> >
> >  static inline void absorb_lanes64_8(u64 *dst, const byte *in)
> >  {
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 0/3] Upgrade to libgcrypt 1.10.3

2024-05-16 Thread Vladimir 'phcoder' Serbinenko
This series of patches upgrades to libgcrypt 1.10.3
First one just imports libgcrypt tarball as-is
Second one updates import script
Third one add a small adjustments to make it work with GRUB x64

-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] elf: accept elf files without section header table

2024-05-03 Thread Vladimir 'phcoder' Serbinenko
Hey. Can you describe what exactly are you trying to solve?

Le ven. 3 mai 2024, 17:46, Mathieu Mirmont  a écrit :

> It isn't an error for an elf executable to be lacking a section header
> table. In this case we should just be returning shnum = 0.
>
> According to the elf(5) manual page:
> "
> e_shoff  This member holds the section header table's file offset in
>bytes. If the file has no section header table, this member
>holds zero.
> "
>
> Signed-off-by: Mathieu Mirmont 
> ---
>   grub-core/kern/elfXX.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
> index aabf4b9d7..fe4ffb261 100644
> --- a/grub-core/kern/elfXX.c
> +++ b/grub-core/kern/elfXX.c
> @@ -220,12 +220,12 @@ grub_elfXX_get_shnum (ElfXX_Ehdr *e, ElfXX_Shnum
> *shnum)
> if (e == NULL)
>   return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("NULL pointer passed
> for elf header"));
>
> +  if (e->e_shoff == 0)
> +return GRUB_ERR_NONE;
> +
> *shnum = e->e_shnum;
> if (*shnum == SHN_UNDEF)
>   {
> -  if (e->e_shoff == 0)
> -
> return grub_error (GRUB_ERR_BAD_NUMBER, N_("invalid section header
> table offset in e_shoff"));
> -
> s = (ElfXX_Shdr *) ((grub_uint8_t *) e + e->e_shoff);
> *shnum = s->sh_size;
> if (*shnum < SHN_LORESERVE)
> --
> 2.30.2
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 1/2] fs/erofs: Add support for EROFS

2024-05-01 Thread Vladimir 'phcoder' Serbinenko
On Tue, Apr 30, 2024 at 4:27 PM Yifan Zhao  wrote:
>
>
>> +  err = grub_disk_read (disk, EROFS_SUPER_OFFSET >> GRUB_DISK_SECTOR_BITS, 
>> 0,
>> +   sizeof (sb), );
>> +  if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
>> +grub_error (GRUB_ERR_BAD_FS, "not a valid erofs filesystem");
>
> OUT_OF_RANGE is already treated the same asBAD_FS in context of opening a file
>>
>>
>
> Sorry, I didn't fully understand that. I copied similar logic from the ext2 
> driver (fs/ext2.c).
>
> Are you suggesting that I should remove the error code conversion here?
>

Yes. Since 2012 (commit bfb320c644e2a3ea463f8bbf72507b2f7b7132d0) this
logic is no longer necessary. ext2 has this logic back from 2009 and
probably should be removed by now

>
> All the other suggestions are great, I will reply in subsequent emails.
>
>
> Thanks,
>
> Yifan Zhao



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 1/2] fs/erofs: Add support for EROFS

2024-04-29 Thread Vladimir 'phcoder' Serbinenko
Generally looks good. Few comments. I have missed part of discussion, so
point me to relevant parts of it if I miss something that's already been
discussed

Le mer. 24 avr. 2024, 14:31, Yifan Zhao  a écrit :
De qq,

> +  struct grub_erofs_super *sb = >data->sb;
> +
> +  return (grub_le_to_cpu32 (sb->meta_blkaddr) << sb->log2_blksz) +
> (node->ino << EROFS_ISLOTBITS);
>
Here you have an overflow. You shift 32-bit value and so it's shifted as
32-bit and only then it's implicitly cast to 64-bit. You need an explicit
cast before shift but after bytesesp for meta_blkaddr.

+}
> +
> +static grub_err_t
> +erofs_read_inode (struct grub_erofs_data *data, grub_fshelp_node_t node)
> +{
> +  struct grub_erofs_inode_compact *dic;
> +  grub_err_t err;
> +  grub_uint16_t i_format;
> +  grub_uint64_t addr = erofs_iloc (node);
> +
> +  dic = (struct grub_erofs_inode_compact *) >inode;
>
Why not use union member here?


> +static grub_uint64_t
> +erofs_inode_file_size (grub_fshelp_node_t node)
> +{
> +  struct grub_erofs_inode_compact *dic = (struct grub_erofs_inode_compact
> *) >inode;
>
Ditto

>
>
+  grub_uint32_t blocksz = erofs_blocksz (node->data);
> +
> +  file_size = erofs_inode_file_size (node);
> +  nblocks = (file_size + blocksz - 1) >> node->data->sb.log2_blksz;
> +  lastblk = nblocks - tailendpacking;
> +
> +  map->m_flags = EROFS_MAP_MAPPED;
> +
> +  if (map->m_la < (lastblk * blocksz))
>
Is this multiplication checked somewhere?

+{
> +  if (grub_mul (grub_le_to_cpu32 (node->inode.i_u.raw_blkaddr),
> blocksz, >m_pa) ||
>
Missing cast to 64-bit.

+ grub_add (map->m_pa, map->m_la, >m_pa))
> +   return GRUB_ERR_OUT_OF_RANGE;
>
It looks like you miss a grub_error

+  if (grub_sub (lastblk * blocksz, map->m_la, >m_plen))
>
Ditto

> +   return GRUB_ERR_OUT_OF_RANGE;
>
Ditto. I stop reviewing this particular construct

+}
> +  else if (tailendpacking)
> +{
> +  if (grub_add (erofs_iloc (node), erofs_inode_size (node),
> >m_pa) ||
> + grub_add (map->m_pa, erofs_inode_xattr_ibody_size (node),
> >m_pa) ||
> + grub_add (map->m_pa, map->m_la % blocksz, >m_pa))
> +   return GRUB_ERR_OUT_OF_RANGE;
> +  if (grub_sub (file_size, map->m_la, >m_plen))
> +   return GRUB_ERR_OUT_OF_RANGE;
> +
> +  if (((map->m_pa % blocksz) + map->m_plen) > blocksz)
>
Addition not checked. If there is a reason it can't overflow even if FS is
maliciously corrupted, please add it in the comment

>
>
> +  pos = ALIGN_UP (pos, unit);
>
Potential overflow if pos is only slightly under it's limit.

+  if (grub_add (pos, chunknr * unit, ))
>
Does this multiplication need verification?

> +
> +  if (chunk_format & EROFS_CHUNK_FORMAT_INDEXES)
> +{
> +  struct grub_erofs_inode_chunk_index idx;
> +  grub_uint32_t blkaddr;
>
I recommend making it 64-bit to avoid casts

> +   {
> + map->m_pa = blkaddr << node->data->sb.log2_blksz;
>
Overflow again.

> +   {
> + map->m_pa = blkaddr << node->data->sb.log2_blksz;
>
Overflow

> +
> +  eend = grub_min (offset + size, map.m_la + map.m_llen);
>
Where is it checked that m_la+m_llen don't overflow? It can be checked when
you read in the  map it should be trimmed or error-out

> +  file_size = erofs_inode_file_size (dir);
> +  buf = grub_malloc (blocksz);
> +  if (!buf)
> +{
> +  grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
>

No need for grub_error: malloc already does it.

> + else
> +   de_namelen = grub_le_to_cpu16 (de[1].nameoff) - nameoff;
>

 This needs a check that it's not negative

> +
>
+  err = grub_disk_read (disk, EROFS_SUPER_OFFSET >> GRUB_DISK_SECTOR_BITS,
> 0,
> +   sizeof (sb), );
> +  if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
> +grub_error (GRUB_ERR_BAD_FS, "not a valid erofs filesystem");
>
OUT_OF_RANGE is already treated the same asBAD_FS in context of opening a
file

>
> +  if (!data)
> +{
> +  grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
>
Ditto

> +static grub_ssize_t
> +grub_erofs_read (grub_file_t file, char *buf, grub_size_t len)
> +{
> +  struct grub_erofs_data *data = file->data;
> +  struct grub_fshelp_node *inode = >inode;
> +  grub_off_t off = file->offset;
> +  grub_uint64_t ret = 0, file_size;
> +  grub_err_t err;
> +
> +  if (!inode->inode_loaded)
> +{
> +  err = erofs_read_inode (data, inode);
> +  if (err != GRUB_ERR_NONE)
> +   {
> + grub_error (GRUB_ERR_IO, "cannot read @ inode %"
> PRIuGRUB_UINT64_T, inode->ino);
>
Any reason to transform error? This could be something else than I/O error.
Why not just propagate it?


> +
> +  err = erofs_read_raw_data (inode, (grub_uint8_t *) buf, len, off, );
> +  if (err != GRUB_ERR_NONE)
> +{
> +  grub_error (GRUB_ERR_IO, "cannot read file @ inode %"
> PRIuGRUB_UINT64_T, inode->ino);
>
Again, I propose to just propagate underlying error.


>
> +grub_size_t
> +grub_strnlen (const char *s, grub_size_t n)
>
Already said in a 

Re: [PATCH v8 1/2] fs/erofs: Add support for EROFS

2024-04-28 Thread Vladimir 'phcoder' Serbinenko
Not a full review. Please don't put new functions like strnlen into kernel
of they are useful only to one module. Kernel size is restricted to a
different degree on some platforms

Le mer. 24 avr. 2024, 14:31, Yifan Zhao  a écrit :

> EROFS [1] is a lightweight read-only filesystem designed for performance
> which has already been shipped in most Linux distributions as well as
> widely
> used in several scenarios, such as Android system partitions, container
> images, and rootfs for embedded devices.
>
> This patch brings EROFS uncompressed support. Now, it's possible to boot
> directly through GRUB with an EROFS rootfs.
>
> EROFS compressed files will be supported later since it has more work to
> polish.
>
> [1] https://erofs.docs.kernel.org
>
> Signed-off-by: Yifan Zhao 
> ---
>  INSTALL |   8 +-
>  Makefile.util.def   |   1 +
>  docs/grub.texi  |   3 +-
>  grub-core/Makefile.core.def |   5 +
>  grub-core/fs/erofs.c| 984 
>  grub-core/kern/misc.c   |  14 +
>  include/grub/misc.h |   1 +
>  7 files changed, 1011 insertions(+), 5 deletions(-)
>  create mode 100644 grub-core/fs/erofs.c
>
> diff --git a/INSTALL b/INSTALL
> index 8d9207c84..84030c9f4 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -77,15 +77,15 @@ Prerequisites for make-check:
>
>  * If running a Linux kernel the following modules must be loaded:
>- fuse, loop
> -  - btrfs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
> +  - btrfs, erofs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix,
> nilfs2,
>  reiserfs, udf, xfs
>- On newer kernels, the exfat kernel modules may be used instead of the
>  exfat FUSE filesystem
>  * The following are Debian named packages required mostly for the full
>suite of filesystem testing (but some are needed by other tests as
> well):
> -  - btrfs-progs, dosfstools, e2fsprogs, exfat-utils, f2fs-tools, genromfs,
> -hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs,
> squashfs-tools,
> -reiserfsprogs, udftools, xfsprogs, zfs-fuse
> +  - btrfs-progs, dosfstools, e2fsprogs, erofs-utils, exfat-utils,
> f2fs-tools,
> +genromfs, hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs,
> +squashfs-tools, reiserfsprogs, udftools, xfsprogs, zfs-fuse
>- exfat-fuse, if not using the exfat kernel module
>- gzip, lzop, xz-utils
>- attr, cpio, g++, gawk, parted, recode, tar, util-linux
> diff --git a/Makefile.util.def b/Makefile.util.def
> index 9432365a9..8d3bc107f 100644
> --- a/Makefile.util.def
> +++ b/Makefile.util.def
> @@ -98,6 +98,7 @@ library = {
>common = grub-core/fs/cpio_be.c;
>common = grub-core/fs/odc.c;
>common = grub-core/fs/newc.c;
> +  common = grub-core/fs/erofs.c;
>common = grub-core/fs/ext2.c;
>common = grub-core/fs/fat.c;
>common = grub-core/fs/exfat.c;
> diff --git a/docs/grub.texi b/docs/grub.texi
> index a225f9a88..396f711df 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -353,6 +353,7 @@ blocklist notation. The currently supported filesystem
> types are @dfn{Amiga
>  Fast FileSystem (AFFS)}, @dfn{AtheOS fs}, @dfn{BeFS},
>  @dfn{BtrFS} (including raid0, raid1, raid10, gzip and lzo),
>  @dfn{cpio} (little- and big-endian bin, odc and newc variants),
> +@dfn{EROFS} (only uncompressed support for now),
>  @dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32},
>  @dfn{exFAT}, @dfn{F2FS}, @dfn{HFS}, @dfn{HFS+},
>  @dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files),
> @@ -6267,7 +6268,7 @@ assumed to be encoded in UTF-8.
>  NTFS, JFS, UDF, HFS+, exFAT, long filenames in FAT, Joliet part of
>  ISO9660 are treated as UTF-16 as per specification. AFS and BFS are read
>  as UTF-8, again according to specification. BtrFS, cpio, tar, squash4,
> minix,
> -minix2, minix3, ROMFS, ReiserFS, XFS, ext2, ext3, ext4, FAT (short names),
> +minix2, minix3, ROMFS, ReiserFS, XFS, EROFS, ext2, ext3, ext4, FAT (short
> names),
>  F2FS, RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed
>  to be UTF-8. This might be false on systems configured with legacy charset
>  but as long as the charset used is superset of ASCII you should be able to
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 007ff628e..8b4dbcd66 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1442,6 +1442,11 @@ module = {
>common = fs/odc.c;
>  };
>
> +module = {
> +  name = erofs;
> +  common = fs/erofs.c;
> +};
> +
>  module = {
>name = ext2;
>common = fs/ext2.c;
> diff --git a/grub-core/fs/erofs.c b/grub-core/fs/erofs.c
> new file mode 100644
> index 0..13f92e71a
> --- /dev/null
> +++ b/grub-core/fs/erofs.c
> @@ -0,0 +1,984 @@
> +/* erofs.c - Enhanced Read-Only File System */
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2024 Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or 

Re: [PATCH 1/2] Allow "fallback" to include entries by title, not just number.

2024-04-22 Thread Vladimir 'phcoder' Serbinenko
Selecting by title is deprecated and kept only for compatibility. Please
use id instead

Le lun. 22 avr. 2024, 17:56, Marek Marczykowski-Górecki <
marma...@invisiblethingslab.com> a écrit :

> From: Peter Jones 
>
> Resolves: rhbz#1026084
>
> Signed-off-by: Peter Jones 
> ---
>  grub-core/normal/menu.c | 85 --
>  1 file changed, 58 insertions(+), 27 deletions(-)
>
> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
> index 6a90e09..6444ee6 100644
> --- a/grub-core/normal/menu.c
> +++ b/grub-core/normal/menu.c
> @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout)
>  }
>  }
>
> +static int
> +menuentry_eq (const char *id, const char *spec)
> +{
> +  const char *ptr1, *ptr2;
> +  ptr1 = id;
> +  ptr2 = spec;
> +  while (1)
> +{
> +  if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
> +   return ptr2 - spec;
> +  if (*ptr2 == '>' && ptr2[1] != '>')
> +   return 0;
> +  if (*ptr2 == '>')
> +   ptr2++;
> +  if (*ptr1 != *ptr2)
> +   return 0;
> +  if (*ptr1 == 0)
> +   return ptr1 - id;
> +  ptr1++;
> +  ptr2++;
> +}
> +  return 0;
> +}
> +
>  /* Get the first entry number from the value of the environment variable
> NAME,
> which is a space-separated list of non-negative integers.  The entry
> number
> which is returned is stripped from the value of NAME.  If no entry
> number
> can be found, -1 is returned.  */
>  static int
> -get_and_remove_first_entry_number (const char *name)
> +get_and_remove_first_entry_number (grub_menu_t menu, const char *name)
>  {
>const char *val, *tail;
>int entry;
> +  int sz = 0;
>
>val = grub_env_get (name);
>if (! val)
> @@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name)
>
>entry = (int) grub_strtoul (val, , 0);
>
> +  if (grub_errno == GRUB_ERR_BAD_NUMBER)
> +{
> +  /* See if the variable matches the title of a menu entry.  */
> +  grub_menu_entry_t e = menu->entry_list;
> +  int i;
> +
> +  for (i = 0; e; i++)
> +   {
> + sz = menuentry_eq (e->title, val);
> + if (sz < 1)
> +   sz = menuentry_eq (e->id, val);
> +
> + if (sz >= 1)
> +   {
> + entry = i;
> + break;
> +   }
> + e = e->next;
> +   }
> +
> +  if (sz > 0)
> +   grub_errno = GRUB_ERR_NONE;
> +
> +  if (! e)
> +   entry = -1;
> +}
> +
>if (grub_errno == GRUB_ERR_NONE)
>  {
> -  /* Skip whitespace to find the next digit.  */
> +  if (sz > 0)
> +   tail += sz;
> +
> +  /* Skip whitespace to find the next entry.  */
>while (*tail && grub_isspace (*tail))
> tail++;
>grub_env_set (name, tail);
> @@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
>grub_menu_execute_entry (entry, 1);
>
>/* Deal with fallback entries.  */
> -  while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
> +  while ((fallback_entry = get_and_remove_first_entry_number (menu,
> "fallback"))
>  >= 0)
>  {
>grub_print_error ();
> @@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer
> *viewer)
>viewers = viewer;
>  }
>
> -static int
> -menuentry_eq (const char *id, const char *spec)
> -{
> -  const char *ptr1, *ptr2;
> -  ptr1 = id;
> -  ptr2 = spec;
> -  while (1)
> -{
> -  if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
> -   return 1;
> -  if (*ptr2 == '>' && ptr2[1] != '>')
> -   return 0;
> -  if (*ptr2 == '>')
> -   ptr2++;
> -  if (*ptr1 != *ptr2)
> -   return 0;
> -  if (*ptr1 == 0)
> -   return 1;
> -  ptr1++;
> -  ptr2++;
> -}
> -}
> -
> -
>  /* Get the entry number from the variable NAME.  */
>  static int
>  get_entry_number (grub_menu_t menu, const char *name)
> --
> git-series 0.9.1
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 2/2] Fix menu entry selection based on ID and title

2024-04-22 Thread Vladimir 'phcoder' Serbinenko
I'm unsure whether an id starting with a numeral should be considered valid
at all. Variable named 0x would be incorrect

Le lun. 22 avr. 2024, 17:57, Marek Marczykowski-Górecki <
marma...@invisiblethingslab.com> a écrit :

> From: Peter Jones 
>
> Currently if grub_strtoul(saved_entry_value, NULL, 0) does not return an
> error, we assume the value it has produced is a correct index into our
> menu entry list, and do not try to interpret the value as the "id" or
> "title" .  In cases where "id" or "title" start with a numeral, this
> makes them impossible to use as selection criteria.
>
> This patch splits the search into three phases - matching id, matching
> title, and only once those have been exhausted, trying to interpret the
> ID as a numeral.  In that case, we also require that the entire string
> is numeric, not merely a string with leading numeric characters.
>
> Resolves: rhbz#1640979
>
> Signed-off-by: Peter Jones 
> [javierm: fix menu entry selection based on title]
> Signed-off-by: Javier Martinez Canillas 
> ---
>  grub-core/normal/menu.c | 141 -
>  1 file changed, 71 insertions(+), 70 deletions(-)
>
> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
> index 6444ee6..b0cfa32 100644
> --- a/grub-core/normal/menu.c
> +++ b/grub-core/normal/menu.c
> @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout)
>  }
>
>  static int
> -menuentry_eq (const char *id, const char *spec)
> +menuentry_eq (const char *id, const char *spec, int limit)
>  {
>const char *ptr1, *ptr2;
>ptr1 = id;
>ptr2 = spec;
> -  while (1)
> +  while (limit == -1 || ptr1 - id <= limit)
>  {
>if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
> return ptr2 - spec;
> @@ -178,7 +178,11 @@ menuentry_eq (const char *id, const char *spec)
>if (*ptr2 == '>')
> ptr2++;
>if (*ptr1 != *ptr2)
> -   return 0;
> +   {
> + if (limit > -1 && ptr1 - id == limit && !*ptr1 &&
> grub_isspace(*ptr2))
> +   return ptr1 -id -1;
> + return 0;
> +   }
>if (*ptr1 == 0)
> return ptr1 - id;
>ptr1++;
> @@ -187,6 +191,58 @@ menuentry_eq (const char *id, const char *spec)
>return 0;
>  }
>
> +static int
> +get_entry_number_helper(grub_menu_t menu,
> +   const char * const val, const char ** const tail)
> +{
> +  /* See if the variable matches the title of a menu entry.  */
> +  int entry = -1;
> +  grub_menu_entry_t e;
> +  int i;
> +
> +  for (i = 0, e = menu->entry_list; e; i++)
> +{
> +  int l = 0;
> +  while (val[l] && !grub_isspace(val[l]))
> +   l++;
> +
> +  if (menuentry_eq (e->id, val, l))
> +   {
> + if (tail)
> +   *tail = val + l;
> + return i;
> +   }
> +  e = e->next;
> +}
> +
> +  for (i = 0, e = menu->entry_list; e; i++)
> +{
> +
> +  if (menuentry_eq (e->title, val, -1))
> +   {
> + if (tail)
> +   *tail = NULL;
> + return i;
> +   }
> +  e = e->next;
> +}
> +
> +  if (tail)
> +*tail = NULL;
> +
> +  entry = (int) grub_strtoul (val, tail, 0);
> +  if (grub_errno == GRUB_ERR_BAD_NUMBER ||
> +  (*tail && **tail && !grub_isspace(**tail)))
> +{
> +  entry = -1;
> +  if (tail)
> +   *tail = NULL;
> +  grub_errno = GRUB_ERR_NONE;
> +}
> +
> +  return entry;
> +}
> +
>  /* Get the first entry number from the value of the environment variable
> NAME,
> which is a space-separated list of non-negative integers.  The entry
> number
> which is returned is stripped from the value of NAME.  If no entry
> number
> @@ -196,7 +252,6 @@ get_and_remove_first_entry_number (grub_menu_t menu,
> const char *name)
>  {
>const char *val, *tail;
>int entry;
> -  int sz = 0;
>
>val = grub_env_get (name);
>if (! val)
> @@ -204,50 +259,24 @@ get_and_remove_first_entry_number (grub_menu_t menu,
> const char *name)
>
>grub_error_push ();
>
> -  entry = (int) grub_strtoul (val, , 0);
> -
> -  if (grub_errno == GRUB_ERR_BAD_NUMBER)
> -{
> -  /* See if the variable matches the title of a menu entry.  */
> -  grub_menu_entry_t e = menu->entry_list;
> -  int i;
> -
> -  for (i = 0; e; i++)
> -   {
> - sz = menuentry_eq (e->title, val);
> - if (sz < 1)
> -   sz = menuentry_eq (e->id, val);
> -
> - if (sz >= 1)
> -   {
> - entry = i;
> - break;
> -   }
> - e = e->next;
> -   }
> +  entry = get_entry_number_helper(menu, val, );
> +  if (!(*tail == 0 || grub_isspace(*tail)))
> +entry = -1;
>
> -  if (sz > 0)
> -   grub_errno = GRUB_ERR_NONE;
> -
> -  if (! e)
> -   entry = -1;
> -}
> -
> -  if (grub_errno == GRUB_ERR_NONE)
> +  if (entry >= 0)
>  {
> -  if (sz > 0)
> -   tail += sz;
> -
>/* Skip whitespace to find the next entry.  */
>while (*tail && grub_isspace 

Re: [PATCH] windows: Add _stack_chk_guard/_stack_chk_fail symbols for Windows 64-bit target

2024-04-09 Thread Vladimir 'phcoder' Serbinenko
LGTM. Reviewed-by: Vladimir Serbinenko

Le mar. 9 avr. 2024, 20:56, Daniel Kiper  a écrit :

> Otherwise the GRUB cannot start when stack protector is enabled on EFI
> platforms.
>
> Signed-off-by: Daniel Kiper 
> ---
>  include/grub/stack_protector.h | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/include/grub/stack_protector.h
> b/include/grub/stack_protector.h
> index c88dc00b5..13d2657d9 100644
> --- a/include/grub/stack_protector.h
> +++ b/include/grub/stack_protector.h
> @@ -25,6 +25,10 @@
>  #ifdef GRUB_STACK_PROTECTOR
>  extern grub_addr_t EXPORT_VAR (__stack_chk_guard);
>  extern void __attribute__ ((noreturn)) EXPORT_FUNC (__stack_chk_fail)
> (void);
> +#if defined(_WIN64) && !defined(__CYGWIN__) /* MinGW, Windows 64-bit
> target. */
> +static grub_addr_t __attribute__ ((weakref("__stack_chk_guard")))
> EXPORT_VAR (_stack_chk_guard);
> +static void __attribute__ ((noreturn, weakref("__stack_chk_fail")))
> EXPORT_FUNC (_stack_chk_fail) (void);
> +#endif
>  #endif
>
>  #endif /* GRUB_STACK_PROTECTOR_H */
> --
> 2.11.0
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: New italian language for Grub 2.00-pre1 - 2.06-pre2 - 2.12-rc1

2024-04-06 Thread Vladimir 'phcoder' Serbinenko
Sorry but we don't manage translation repository. Please contact
translationproject. https://translationproject.org/team/it.html

On Fri, Apr 5, 2024 at 10:18 PM bovirus (gmail)  wrote:
>
> HI.
>
>
> Attached
>
>
>
> Italian translation for grub 2.06-pre1 - Translated 100%
>
> Italian translation for grub 2.06-pre2 - Translated 100%
>
> Italian translation for grub 2.12-rc1 - Translated 100%
>
>
>
> Please update in language repository.
>
>
>
> Thanks.
>
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] STACK_PROTECTOR: Support symbols emitted by windows compiler

2024-04-04 Thread Vladimir 'phcoder' Serbinenko
I didn't know about using weakref for this but I'm fine with the approach.
Just one thing: can we condition it on HAVE_ASM_USCORE test instead of
platform?

Le jeu. 4 avr. 2024, 23:47, Daniel Kiper  a écrit :

> Adding Ard, Glenn and Dave...
>
> First of all, sorry for late reply but I was busy with other stuff...
>
> On Fri, Mar 15, 2024 at 09:43:22PM +0300, Vladimir 'phcoder' Serbinenko
> wrote:
> > stack protector needs symbols with just one underscore in C
> > name unlike unix variant that needs double underscore.
> > Supply both symbols for simplicity
> >
> > Signed-off-by: Vladimir Serbinenko 
>
> I do not like your solution because it adds unneeded code/symbols to
> some EFI builds. I come up with two other solutions.
>
> First, let's define an alias when using MinGW build environment:
>
> diff --git a/include/grub/stack_protector.h
> b/include/grub/stack_protector.h
> index c88dc00b5..8d99fd50e 100644
> --- a/include/grub/stack_protector.h
> +++ b/include/grub/stack_protector.h
> @@ -25,6 +25,10 @@
>  #ifdef GRUB_STACK_PROTECTOR
>  extern grub_addr_t EXPORT_VAR (__stack_chk_guard);
>  extern void __attribute__ ((noreturn)) EXPORT_FUNC (__stack_chk_fail)
> (void);
> +#if defined(_WIN32) && !defined(__CYGWIN__)
> +static grub_addr_t __attribute__ ((weakref("__stack_chk_guard")))
> EXPORT_VAR (_stack_chk_guard);
> +static void __attribute__ ((noreturn, weakref("__stack_chk_fail")))
> EXPORT_FUNC (_stack_chk_fail) (void);
> +#endif
>  #endif
>
>  #endif /* GRUB_STACK_PROTECTOR_H */
>
> Tested and it works. We have to use weakref() instead of alias() due to
> definition in separate translation unit.
>
> Second, do not drop leading underscore:
>
> diff --git a/conf/Makefile.common b/conf/Makefile.common
> index b8f216f6c..fd20f6b4e 100644
> --- a/conf/Makefile.common
> +++ b/conf/Makefile.common
> @@ -38,7 +38,7 @@ CCASFLAGS_DEFAULT = $(CPPFLAGS_DEFAULT) -DASM_FILE=1
>  BUILD_CPPFLAGS += $(CPPFLAGS_DEFAULT)
>
>  CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding
> -LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> +LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> -Wl,--leading-underscore
>  CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
>  CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
>  STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R
> .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx
> @@ -51,12 +51,12 @@ endif
>  endif
>
>  CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding
> -LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> -Wl,-r
> +LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> -Wl,-r -Wl,--leading-underscore
>  CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
>  CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
>
>  CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin
> -LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> -Wl,-S
> +LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
> -Wl,-S -Wl,--leading-underscore
>  CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
>  CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
>
> diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in
> index e57c4d920..04b680ad0 100644
> --- a/grub-core/genmod.sh.in
> +++ b/grub-core/genmod.sh.in
> @@ -83,9 +83,9 @@ else
>  for dep in $deps; do echo "char moddep_$dep[] __attribute__
> ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
>
>  if test -n "$deps"; then
> -   @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o
> $tmpfile2 $t1 $t2 $tmpfile -Wl,-r
> +   @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib
> -Wl,--leading-underscore -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r
>  else
> -   @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o
> $tmpfile2 $t1 $tmpfile -Wl,-r
> +   @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib
> -Wl,--leading-underscore -o $tmpfile2 $t1 $tmpfile -Wl,-r
>  fi
>  rm -f $t1 $t2 $tmpfile
>  mv $tmpfile2 $tmpfile
> diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c
> index 11331294f..233118252 100644
> --- a/util/grub-pe2elf.c
> +++ b/util/grub-pe2elf.c
> @@ -71,7 +71,7 @@ insert_string (const char *name)
>  {
>int len, result;
>
> -  if (*name == '_')
> +  if (*name == '_' && !strcmp("__stack_chk_fail", name) &&
> !strcmp("__stack_chk_guard", name))
>  name++;
>
>len = strlen (name);
>
> This one works too. However, it breaks normal builds. So, it requires some
> tweaking to make it production ready.
>
> Anyway, I prefer first solution because it is simpler. I do not mention
> that the second one may break other symbols with leading underscore.
>
> What do you think?
>
> Daniel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] fs/xfs: Handle non-continuous data blocks in directory extents

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
On Sat, Feb 17, 2024 at 12:39 AM Jon DeVree  wrote:
>
> On Thu, Feb 15, 2024 at 20:33:13 +0300, Vladimir 'phcoder' Serbinenko wrote:
> > Is the pointer guaranteed to be aligned? If not you have to use unaligned
> > access.
>
> I don't know what alignment guarantees grub_malloc() makes. As long as
> they are close to what the regular C malloc() guarantees then it should
> be fine.

grub_malloc design guarantees the largest natural alignment of all types.
grub_malloc implementation guarantees alignment of 4 * sizeof(void*).

My concern was that the pointer is moved after alloc but it turns own
it was not the case.
So there are no unaligned access concerns

The code still violates cast-align and strict aliasing invariants but
so is the rest of XFS code.
So I'm happy to merge this patch

Reviewed-By: Vladimir Serbinenko 

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Implement fmap support

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
fmap (flash map) is a partition table used by coreboot. Support it in
order to retrieve the files in non-default partition

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-Implement-fmap-support.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] grub-fstest: Add a new command zfs-bootfs.

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
This is useful to check zfs-bootfs command.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-grub-fstest-Add-a-new-command-zfs-bootfs.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Improve cbfs detection

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
With FMAP and non-continuous SPI old way of reading CBFS pointer
is no longer reliable. Hence use new lbio tags to detect the correct
cbfs layout

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-Improve-cbfs-detection.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add commands for reading and writing raw bytes to CMOS

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
With some coreboot configs setting a byte to a magic value
changes behaviour on next boot. Setting bit-by-bit is
possible but not convenient. Add cmosread and cmoswrite for
convenience.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-Add-commands-for-reading-and-writing-raw-bytes-to-CM.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Enable cmos on x86 EFI

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
CMOS actually exists on most EFI platforms and in some cases used to
store useful data that makes it useful for GRUB to read/write it

As for datetime keep using EFI API and not CMOS

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-Enable-cmos-on-x86-EFI.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2] acpi: Mark MADT entries as packed.

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
No alignment is guaranteed and in fact on my ia64 sapic is aligned
to 4 bytes instead of 8 and causes a trap. It affects only rarely used
lsacpi command and so went unnoticed.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-acpi-Mark-MADT-entries-as-packed.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2] MULTIBOOT: Fix handling of errors in broken aout-kludge

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
Current code in some codepaths neither discards nor reports
errors. Properly surface the error

While on it split 2 cases of unrelated variables both named err.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-MULTIBOOT-Fix-handling-of-errors-in-broken-aout-klud.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] STACK_PROTECTOR: Support symbols emitted by windows compiler

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
stack protector needs symbols with just one underscore in C
name unlike unix variant that needs double underscore.
Supply both symbols for simplicity

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-STACK_PROTECTOR-Support-symbols-emitted-by-windows-c.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 2/6] ieee1275/powerpc: enables device mapper discovery

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
On Mon, May 8, 2023 at 5:01 PM Avnish Chouhan  wrote:
>
> From: Diego Domingos 
>
> This patch enables the device mapper discovery on ofpath.c. Currently,
> when we are dealing with a device like /dev/dm-* the ofpath returns null
> since there is no function implemented to handle this case.
Why is this result incorrect? Does your OFW handle device-mapper? If
it doesn't then the answer to "what is the OFW path of dm-*?" is
"none" and null is the correct return

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 3/7] multiboot2: Add support for the load type header tag

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
Not a full review. Just one blocking problem


>
>  }
> +  case MULTIBOOT_LOAD_TYPE_PE:
> +  grub_fatal ("Unsupported load type: %u\n", mld.load_type);
> +  default:
> +/* should be impossible */
> +grub_fatal ("Unknown load type: %u\n", mld.load_type);
>
Don't use grub_fatal for this. grub_fatal is only when continue to execute
grub is unwise. Here you just have an unsupported file. This is definitely
a GRUB_ERR_BAD_OS


>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 7/7] verifiers: Verify after decompression

2024-03-15 Thread Vladimir 'phcoder' Serbinenko
Verifying after decompression is a bad security practice. It relies on
decompression having no security holes. Given how complex decompression is,
this is almost guaranteed to be false.

Le mer. 13 mars 2024, 18:08, Ross Lagerwall via Grub-devel <
grub-devel@gnu.org> a écrit :

> It is convenient and common to have binaries stored in gzip archives
> (e.g. xen.gz). Verification should be run after decompression rather
> than before so reorder the file filter list as appropriate.
>
> Signed-off-by: Ross Lagerwall 
> ---
>  include/grub/file.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/grub/file.h b/include/grub/file.h
> index a5bf3a792d6f..a1ef3582bc7b 100644
> --- a/include/grub/file.h
> +++ b/include/grub/file.h
> @@ -182,10 +182,10 @@ extern grub_disk_read_hook_t
> EXPORT_VAR(grub_file_progress_hook);
>  /* Filters with lower ID are executed first.  */
>  typedef enum grub_file_filter_id
>{
> -GRUB_FILE_FILTER_VERIFY,
>  GRUB_FILE_FILTER_GZIO,
>  GRUB_FILE_FILTER_XZIO,
>  GRUB_FILE_FILTER_LZOPIO,
> +GRUB_FILE_FILTER_VERIFY,
>  GRUB_FILE_FILTER_MAX,
>  GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
>  GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
> --
> 2.43.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

2024-03-14 Thread Vladimir 'phcoder' Serbinenko
Please take this discussion to a separate thread. In this thread it's
pure offtopic

On Thu, Mar 14, 2024 at 10:25 AM Jan Beulich via Grub-devel
 wrote:
>
> On 13.03.2024 16:07, Ross Lagerwall wrote:
> > In addition to the existing address and ELF load types, specify a new
> > optional PE binary load type. This new type is a useful addition since
> > PE binaries can be signed and verified (i.e. used with Secure Boot).
>
> And the consideration to have ELF signable (by whatever extension to
> the ELF spec) went nowhere?
>
> Jan
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 0/4] More ls improvements

2024-03-01 Thread Vladimir 'phcoder' Serbinenko
Le ven. 6 oct. 2023, 10:25, Glenn Washburn  a
écrit :

> On Thu, 14 Sep 2023 15:08:00 -0500
> Glenn Washburn  wrote:
>
> > On Thu, 14 Sep 2023 17:37:10 +0200
> > "Vladimir 'phcoder' Serbinenko"  wrote:
> >
> > > Le lun. 14 août 2023, 20:58, Glenn Washburn <
> developm...@efficientek.com> a
> > > écrit :
> > >
> > > > Currently when given a path to a file, ls will open the file to
> determine
> > > > if its is valid and then run the appropriate print function, in
> contrast to
> > > > directory arguments that use the directory iterator and callback on
> each
> > > > file. One issue with this is that opening a file does not allow
> access to
> > > > its modification time information, whereas the info object from the
> > > > callback
> > > > called by the directory iterator does and the longlist print
> function will
> > > > print the modification time if present. The result is that when
> longlisting
> > > > ls arguments, directory arguments show moditication times but file
> > > > arguments
> > > > do not. Patch 2 rectifies this an in the process simplifies the code
> path
> > > > by using the directory iterator for file arguments as well.
> > > >
> > > > The implementation of patch 2 exposed a bug in grub_disk_read()
> which is
> > > > fixed in patch 1.
> > > >
> > > > Patches 3 and 4 aim to make the output of GRUB's ls look more like
> GNU's
> > > > ls output. And patch 4 also fixes an issue where there are blank
> lines
> > > > between consecutive file arguments.
> > > >
> > > > Glenn
> > > >
> > > > Glenn Washburn (4):
> > > >   disk: Reset grub_errno upon entering grub_disk_read()
> > > >
> > > Where does the error come from? We generally prefer to have
> > > grub_print_error() (better) or resetting grib_errno after the error is
> > > produced rather than blanketly reset grub_errno at the beginning
> >
> > Take a look at patch 2, you'll see that the changes add another
> > (fs->fs_dir)(...). This added line is in an "if" block that is only
> > entered when grub_errno is not GRUB_ERR_SUCCESS. So under normal and
> > expected conditions, grub_errno will be set (when there are
> > non-directory arguments). This error is more of a flag than a real
> > error that should be shown the user.
> >
> > The preferred usage policy of grub_errno that you suggest is aligned
> > with "man errno". So it has that going for it. I don't particularly
>
> Actually, I take that back. My reading of the man page leads me to
> conclude that library calls can do what they wish with errno, so I
> think clearing it as in this patch is perfectly reasonable. The man
> page states, if the errno needs to be used across another library call,
> then it must be saved. The same should be expected of grub calls. I'll
> admit its a bit of an apples and oranges comparison, but this makes
> sense to me.
>


While grub_errno is named after posix, it's not designed in the same way.
It's more in line with the design of exceptions. I agree that this
situation is unfortunate and ideally we need to change it centrally. Let me
start a separate thread with possible options for this.

>
> > like it because, for one, I've seen odd read failures in the past that
> > I suspect are due to read returning with an error, when it actually
> > succeed. So it can give false positives that doesn't make sense and are
> > hard to track down. I see a few options here:
> >
> > 1. Have read() return err, instead of grub_errno, but that has a couple
> > problems. First, it probably will then ignore error from the cache
> > code. And second, I've not checked for usages of read() where
> > grub_errno is checked instead of the return value for error, but those
> > might exist as well.
> >
> > 2. Set grub_errno before every call to read(). But then that's not
> > really different that doing that at the start of the function.
> >
> > 3. A compromise option could be to output to the debug log a message
> > saying that read was called with grub_errno set. But that can easily be
> > overflowed, so it might not be noticed. And even if it is seen, what you
> > really care about is the caller, but is there a good way to get that
> > without having a debugger already attached? When the backtrace
> > functionality works again (perhaps soon), that could be used, but only
> > on x86.
> >
> > 4. In this specific in

Re: Need help: alternative module inclusion - duplicate symbols

2024-02-26 Thread Vladimir 'phcoder' Serbinenko
You can add a dispatcher which switches between 2 modules. E.g.
real_do_stuff (...);
fake_do_stuff(...);

static int (*do_stuff)( ...);
And switch pointer between 2 implementations. See terminal output and
grub_xputs for examples

On Mon, Feb 26, 2024 at 1:51 PM Michael Lawnick via Grub-devel
 wrote:
>
> Hi group,
>
> hope you can help me:
> I have modules pci_fpga.c and pci_fpga_emul.c with same functions in
> them but different implementation, one for the real device, the other
> one is just emulating.
>
> What I now want is being able to include one of both versions through
> build command. I started with this:
>
> Makefile.core.def:
> ...
> module = {
>   name = pci_fpga;
>   common = startlib/board/pci_fpga.c;
>   enable = efi;
> };
>
> module = {
>   name = pci_fpga_emul;
>   common = startlib/board/pci_fpga_emul.c;
>   enable = efi;
> };
> ...
>
> but then I get duplicate symbols error even without giving pci_fpga or
> pci_fpga_emul on the build.
>
> For using different packages than 'common' like this
> module = {
>   name = pci_fpga;
>   pci_fpga = startlib/board/pci_fpga.c;
>   enable = efi;
> };
> I could not find means to get pci_fpga included.
>
> Same problem if trying to approach it via different enable flag: How to do?
>
> Can anybody help? In docs I couldn't find usable hints.
>
> --
> KR
> Michael
>
> _______
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] efidisk: Breakup large reads into batches

2024-02-23 Thread Vladimir 'phcoder' Serbinenko
Why is setting max_agglomerate not enough to achieve the same effect?

On Fri, Feb 23, 2024 at 8:12 PM Mate Kukri  wrote:
>
> From: David F 
>
> Work around firmware bugs that cause large reads to fail from certain
> devices.
>
> Report-By: David F 
> Signed-off-by: Mate Kukri 
> ---
>  grub-core/disk/efi/efidisk.c | 43 +---
>  1 file changed, 30 insertions(+), 13 deletions(-)
>
> diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
> index 3b5ed5691..079b72ab7 100644
> --- a/grub-core/disk/efi/efidisk.c
> +++ b/grub-core/disk/efi/efidisk.c
> @@ -27,6 +27,9 @@
>  #include 
>  #include 
>
> +/* break up io to prevent problems under some UEFI envrionments */
> +#define EFIDISK_C_MAXIOSECS 0x100U
> +
>  struct grub_efidisk_data
>  {
>grub_efi_handle_t handle;
> @@ -599,20 +602,34 @@ grub_efidisk_read (struct grub_disk *disk, 
> grub_disk_addr_t sector,
>grub_size_t size, char *buf)
>  {
>grub_efi_status_t status;
> +  grub_size_t sector_count;
>
> -  grub_dprintf ("efidisk",
> -   "reading 0x%lx sectors at the sector 0x%llx from %s\n",
> -   (unsigned long) size, (unsigned long long) sector, 
> disk->name);
> -
> -  status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
> -
> -  if (status == GRUB_EFI_NO_MEDIA)
> -return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), 
> disk->name);
> -  else if (status != GRUB_EFI_SUCCESS)
> -return grub_error (GRUB_ERR_READ_ERROR,
> -  N_("failure reading sector 0x%llx from `%s'"),
> -  (unsigned long long) sector,
> -  disk->name);
> +  /* break up reads to EFIDISK_C_MAXIOSECS size chunks */
> +  do
> +{
> +  /* determine number of sectors this cycle */
> +  sector_count = (size > EFIDISK_C_MAXIOSECS) ? EFIDISK_C_MAXIOSECS : 
> size;
> +
> +  /* output debug information */
> +  grub_dprintf ("efidisk",
> +   "reading 0x%lx sectors at the sector 0x%llx from %s\n",
> +   (unsigned long) sector_count, (unsigned long long) 
> sector, disk->name);
> +
> +  status = grub_efidisk_readwrite (disk, sector, sector_count, buf, 0);
> +
> +  if (status == GRUB_EFI_NO_MEDIA)
> +   return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), 
> disk->name);
> +  if (status != GRUB_EFI_SUCCESS)
> +   return grub_error (GRUB_ERR_READ_ERROR,
> +  N_("failure reading 0x%lx sector(s) from sector 
> 0x%llx on `%s'"),
> +  (unsigned long) sector_count, (unsigned long long) 
> sector, disk->name);
> +
> +  /* next cycle */
> +  buf += (grub_efi_uintn_t) sector_count << disk->log_sector_size;;
> +  sector += sector_count;
> +  size -= sector_count;
> +}
> +  while (size);
>
>return GRUB_ERR_NONE;
>  }
> --
> 2.39.2
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Failed to build with "-mretpoline"

2024-02-22 Thread Vladimir 'phcoder' Serbinenko
Hello. Why does it create duplicate global symbols? How does LD handle the
same situation?

Le ven. 9 févr. 2024, 16:58, Oleksiy Obitotskyi -X (oobitots - GLOBALLOGIC
INC at Cisco) via Grub-devel  a écrit :

> Hi,
>
> We are bulding grub with clang that use -mretpoline option. This leads to
> symbols __llvm_retpoline_[eax/ecx/edx, etc.] generated into binaries. And
> caused  duplicates error during moddep.lst creation.
> I'm not sure if this fix will be a bit project specific?
>
> diff --git a/grub-core/genmoddep.awk b/grub-core/genmoddep.awk
> index 2474363..f859854 100644
> --- a/grub-core/genmoddep.awk
> +++ b/grub-core/genmoddep.awk
> @@ -18,7 +18,7 @@ BEGIN {
> {
> if ($1 == "defined") {
> - if ($3 !~ /^\.refptr\./ && $3 in symtab) {
> + if ($3 !~ /__llvm_retpoline_.*/ && $3 !~ /^\.refptr\./ && $3 in symtab) {
> printf "%s in %s is duplicated in %s\n", $3, $2, symtab[$3] >"/dev/stderr";
> error++;
> }
>
> Regards,
> Oleksiy
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] MULTIBOOT: Fix handling of errors in broken aout-kludge

2024-02-20 Thread Vladimir 'phcoder' Serbinenko
-- 
Regards
Vladimir 'phcoder' Serbinenko


0001-MULTIBOOT-Fix-handling-of-errors-in-broken-aout-klud.patch
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] fs/xfs: Handle non-continuous data blocks in directory extents

2024-02-15 Thread Vladimir 'phcoder' Serbinenko
Is the pointer guaranteed to be aligned? If not you have to use unaligned
access. Any reason not to check it against correct magic and not just
zero-out?

Le dim. 11 févr. 2024, 18:36, Jon DeVree  a écrit :

> The directory extent list does not have to be a continuous list of data
> blocks. When GRUB tries to read a non-existant member of the list,
> grub_xfs_read_file() will return a block of zero'ed memory. Checking for
> a zero'ed magic number is sufficient to skip this non-existant data
> block.
>
> Prior to commit 07318ee7e this was handled as a subtle side effect of
> reading the (non-existant) tail data structure. Since the block was
> zero'ed the computation of the number of directory entries in the block
> would return 0 as well.
>
> Fixes: 07318ee7e (fs/xfs: Fix XFS directory extent parsing)
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2254370
> Signed-off-by: Jon DeVree 
> ---
>  grub-core/fs/xfs.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
> index bc2224dbb..a6cce9cfe 100644
> --- a/grub-core/fs/xfs.c
> +++ b/grub-core/fs/xfs.c
> @@ -902,6 +902,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
> grub_xfs_first_de(dir->data,
> dirblock);
> int entries = -1;
> char *end = dirblock + dirblk_size;
> +   grub_uint32_t magic;
>
> numread = grub_xfs_read_file (dir, 0, 0,
>   blk << dirblk_log2,
> @@ -912,6 +913,15 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
> return 0;
>   }
>
> +   /*
> +* If this data block isn't actually part of the extent list
> then
> +* grub_xfs_read_file() returns a block of zeros. So if the
> magic number
> +* field is all zeros then this block should be skipped.
> +*/
> +   magic = *(grub_uint32_t *)dirblock;
> +   if (!magic)
> + continue;
> +
> /*
>  * Leaf and tail information are only in the data block if the
> number
>  * of extents is 1.
> --
> 2.43.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Critical Boot Loader Vulnerability in Shim Impacts Nearly All Linux Distros

2024-02-08 Thread Vladimir 'phcoder' Serbinenko
Shim is not a component of grub

Le ven. 9 févr. 2024, 07:41, Turritopsis Dohrnii Teo En Ming via Grub-devel
 a écrit :

> Subject: Critical Boot Loader Vulnerability in Shim Impacts Nearly All
> Linux Distros
>
> Good day from Singapore,
>
> I have just come across this article.
>
> Article: Critical Boot Loader Vulnerability in Shim Impacts Nearly All
> Linux Distros
> Link:
> https://thehackernews.com/2024/02/critical-bootloader-vulnerability-in.html
>
> May I know if Shim is an important component of GNU Grub?
>
> Thank you.
>
> Regards,
>
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
> Blogs:
> https://tdtemcerts.blogspot.com
> https://tdtemcerts.wordpress.com
> GIMP also stands for Government-Induced Medical Problems.
>
>
>
>
>
>
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v3 2/2] disk: increase sector size up to 127 for LBA reads

2024-02-08 Thread Vladimir 'phcoder' Serbinenko
I have few concerns:
1. The name of your patch is misleading. You don't increase sector size
2. This increases memory pressure on systems that are already low on usable
memory. Sparc64 comes to mind. Due to the way how off handles memory map
there, even if you have a terabyte of RAM, only few MiB are usable at boot.
We may need to do it dynamically, otherwise we either leave a lot of gain
on systems that can read megabytes at once or we fail on low memory systems
3. Firmware bugs. Not even just BIOS. This changes all the systems. We need
to review all the drivers
4. You mentioned that other implementations that increase the size of
single read have a fallback. Do we have one?

Le mar. 10 oct. 2023, 21:30, ValdikSS via Grub-devel  a
écrit :

> Increase the value from 63 to speed up reading process.
>
> This commit increases two limits: the low-level int 13h reading code
> and a high-level reading code with disk cache.
> The disk cache imposes an overall limitation of a higher-layer reading
> code. The original comment regarding 16K is incorrect, it was
> 512<<6 = 32768, and now it is 512<<7 = 65536.
>
> According to [Wikipedia][1] and [OSDev][2], the upper safe value for LBA
> read using IBM/MS INT13 Extensions is 127 sectors due to the
> limitations of some BIOSes.
> GRUB [already enforced][3] the limit, but it was no-op due to other
> constraints. This value is also used in [syslinux][4].
>
> As we're now reading up to 127 sectors of 512 bytes, we need to be able
> to store in the cache up to 65024 bytes. Without this change, GRUB
> wouldn't try to read more than 64 sectors at once
> (even if the lower reading layer allows it).
>
> [1]:
> https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=42h:_Extended_Read_Sectors_From_Drive
> [2]:
> https://wiki.osdev.org/Disk_access_using_the_BIOS_(INT_13h)#LBA_in_Extended_Mode
> [3]:
> https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/disk/i386/pc/biosdisk.c?h=grub-2.12-rc1#n430
> [4]:
> https://repo.or.cz/syslinux.git/blob/refs/tags/syslinux-6.03:/core/fs/diskio_bios.c#l349
>
> Signed-off-by: ValdikSS 
> ---
>  include/grub/disk.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/grub/disk.h b/include/grub/disk.h
> index be032a72c..608deb034 100644
> --- a/include/grub/disk.h
> +++ b/include/grub/disk.h
> @@ -184,14 +184,14 @@ typedef struct grub_disk_memberlist
> *grub_disk_memberlist_t;
>  #define GRUB_MDRAID_MAX_DISKS  4096
>
>  /* The size of a disk cache in 512B units. Must be at least as big as the
> -   largest supported sector size, currently 16K.  */
> -#define GRUB_DISK_CACHE_BITS   6
> +   largest supported sector size, currently 64K.  */
> +#define GRUB_DISK_CACHE_BITS   7
>  #define GRUB_DISK_CACHE_SIZE   (1 << GRUB_DISK_CACHE_BITS)
>
>  #define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS -
> GRUB_DISK_SECTOR_BITS)) - 1)
>
>  /* Maximum number of sectors to read in LBA mode at once */
> -#define GRUB_DISK_MAX_LBA_SECTORS 63
> +#define GRUB_DISK_MAX_LBA_SECTORS 127
>
>  /* Return value of grub_disk_native_sectors() in case disk size is
> unknown. */
>  #define GRUB_DISK_SIZE_UNKNOWN  0xULL
> --
> 2.41.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: State of Argon2 support

2024-01-26 Thread Vladimir 'phcoder' Serbinenko
Le ven. 26 janv. 2024, 20:50, Daniel Kiper  a écrit :

> On Fri, Jan 26, 2024 at 03:18:57AM -0500, Nikolaos Chatzikonstantinou
> wrote:
> > On Thu, Jan 25, 2024 at 1:15 PM Daniel Kiper 
> wrote:
> > >
> > > Adding Vladimir who knows GRUB history better than I...
> > >
> > > On Wed, Jan 24, 2024 at 01:23:55AM -0500, Nikolaos Chatzikonstantinou
> wrote:
> > >
> > > [...]
> > >
> > > > My apologies for the repeated messages, but I came up with just one
> > > > more question that I'm curious about. To summarize my questions:
> > > >
> > > > 1. Where is the libgcrypt bundle from grub from? I think my
> > > > investigation has led me around version 1.7.0 of libgcrypt, but if I
> > > > can get a precise commit or version, that would be useful.
> > > >
> > > > ... and now to my new question:
> > >
> > > Vladimir, could you help with that?
> > >
> > > > 2. What is the reason libgcrypt is bundled as opposed to a regular
> dependency?
> > >
> > > I am not entirely sure I understand the question. Could you elaborate?
> >
> > By bundling, I mean that someone copied libgcrypt files into the GRUB
> project.
> >
> > To elaborate further, regular programs (not like GRUB which is a
> > bootloader) can link statically or dynamically to libraries; but also,
> > there's a third option, to dump the source code of a library directly
> > into the source tree of the project. To my understanding this third
> > option (which is not really a third linker option as it is not related
> > to the linker) is chosen when the project needs to include its own
> > patch set to the library. I am curious if GRUB has patched libgcrypt
> > for some reason, and is that why libgcrypt is bundled with GRUB?
>
> I think Vladimir could tell us more here...
>
> Anyway, I think we should avoid patching libgcrypt, or any given library
> merged with GRUB source, as much as possible.
>
This was my goal as well. Almost all the changes are difficult to avoid.
But at least they are automated in most cases. See import_gcry script. I'm
not on my computer now. I hope to find a time to have a look until the end
of next week.

>
> Daniel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] cli_lock: Added build option to block command line interface

2024-01-26 Thread Vladimir 'phcoder' Serbinenko
Le ven. 26 janv. 2024, 23:15, Daniel Kiper  a écrit :

> On Fri, Jan 26, 2024 at 02:12:31AM +0300, Vladimir 'phcoder' Serbinenko
> wrote:
> > Please detail your use case. GRUB already had user framework in the same
> > problem space.
>
> I am not sure what exactly you mean by "user framework". Could you
> elaborate or point us code examples?
>

https://www.gnu.org/software/grub/manual/grub/grub.html#Authentication-and-authorisation

>
> Anyway, we need a mechanism to disallow access to CLI, arguments editing
> for kernels, etc. I.e. user cannot change widely understood boot config
> even being at the console.
>
Yes and it's exactly what happens as soon as superuser is set. Basically
this patch is equivalent to having a superuser without a valid password.
AFAIR it's achieved by setting superuser's but not issuing password
commands. If not we can have password_deny command.

>
> Daniel
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] cli_lock: Added build option to block command line interface

2024-01-25 Thread Vladimir 'phcoder' Serbinenko
Please detail your use case. GRUB already had user framework in the same
problem space.

Le mer. 24 janv. 2024, 09:27, Alec Brown  a écrit :

> Added functionality to disable command line interface access and editing
> of GRUB
> menu entries if GRUB image is built with --disable-cli.
>
> Signed-off-by: Alec Brown 
> ---
>  docs/grub.texi |  6 --
>  grub-core/kern/main.c  | 28 
>  grub-core/kern/rescue_reader.c | 13 +
>  grub-core/normal/auth.c|  3 +++
>  grub-core/normal/menu_text.c   | 31 +--
>  include/grub/kernel.h  |  3 ++-
>  include/grub/misc.h|  2 ++
>  include/grub/util/install.h|  8 ++--
>  util/grub-install-common.c | 11 ---
>  util/grub-mkimage.c|  9 -
>  util/mkimage.c | 16 +++-
>  11 files changed, 106 insertions(+), 24 deletions(-)
>
> diff --git a/docs/grub.texi b/docs/grub.texi
> index a225f9a88..96ab17d5b 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -6412,8 +6412,10 @@ the GRUB command line, edit menu entries, and
> execute any menu entry.  If
>  @samp{superusers} is set, then use of the command line and editing of menu
>  entries are automatically restricted to superusers. Setting
> @samp{superusers}
>  to empty string effectively disables both access to CLI and editing of
> menu
> -entries. Note: The environment variable needs to be exported to also
> affect
> -the section defined by the @samp{submenu} command (@pxref{submenu}).
> +entries. Building a grub image with @samp{--disable-cli} option will also
> +disable access to CLI and editing of menu entries, as well as disabling
> rescue
> +mode. Note: The environment variable needs to be exported to also affect
> the
> +section defined by the @samp{submenu} command (@pxref{submenu}).
>
>  Other users may be allowed to execute specific menu entries by giving a
> list of
>  usernames (as above) using the @option{--users} option to the
> diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
> index 731c07c29..30643164e 100644
> --- a/grub-core/kern/main.c
> +++ b/grub-core/kern/main.c
> @@ -30,11 +30,14 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #ifdef GRUB_MACHINE_PCBIOS
>  #include 
>  #endif
>
> +static bool cli_disabled = false;
> +
>  grub_addr_t
>  grub_modules_get_end (void)
>  {
> @@ -237,6 +240,28 @@ grub_load_normal_mode (void)
>grub_command_execute ("normal", 0, 0);
>  }
>
> +bool
> +grub_is_cli_disabled (void)
> +{
> +  return cli_disabled;
> +}
> +
> +static void
> +check_is_cli_disabled (void)
> +{
> +  struct grub_module_header *header;
> +  header = 0;
> +
> +  FOR_MODULES (header)
> +{
> +  if (header->type == OBJ_TYPE_DISABLE_CLI)
> +   {
> + cli_disabled = true;
> + return;
> +   }
> +}
> +}
> +
>  static void
>  reclaim_module_space (void)
>  {
> @@ -294,6 +319,9 @@ grub_main (void)
>
>grub_boot_time ("After loading embedded modules.");
>
> +  /* Check if the CLI should be disabled */
> +  check_is_cli_disabled ();
> +
>/* It is better to set the root device as soon as possible,
>   for convenience.  */
>grub_set_prefix_and_root ();
> diff --git a/grub-core/kern/rescue_reader.c
> b/grub-core/kern/rescue_reader.c
> index dcd7d4439..4259857ba 100644
> --- a/grub-core/kern/rescue_reader.c
> +++ b/grub-core/kern/rescue_reader.c
> @@ -78,6 +78,19 @@ grub_rescue_read_line (char **line, int cont,
>  void __attribute__ ((noreturn))
>  grub_rescue_run (void)
>  {
> +  /* Stall if the CLI has been disabled */
> +  if (grub_is_cli_disabled ())
> +{
> +  grub_printf ("Rescue mode has been disabled...\n");
> +
> +  do
> +   {
> + /* Do not optimize out the loop. */
> + asm volatile ("");
> +   }
> +  while (1);
> +}
> +
>grub_printf ("Entering rescue mode...\n");
>
>while (1)
> diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c
> index 517fc623f..d94020186 100644
> --- a/grub-core/normal/auth.c
> +++ b/grub-core/normal/auth.c
> @@ -209,6 +209,9 @@ grub_auth_check_authentication (const char *userlist)
>char entered[GRUB_AUTH_MAX_PASSLEN];
>struct grub_auth_user *user;
>
> +  if (grub_is_cli_disabled ())
> +return GRUB_ACCESS_DENIED;
> +
>grub_memset (login, 0, sizeof (login));
>
>if (is_authenticated (userlist))
> diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c
> index b1321eb26..9c383e64a 100644
> --- a/grub-core/normal/menu_text.c
> +++ b/grub-core/normal/menu_text.c
> @@ -178,21 +178,24 @@ command-line or ESC to discard edits and return to
> the GRUB menu."),
>
>grub_free (msg_translated);
>
> -  if (nested)
> +  if (!grub_is_cli_disabled ())
> {
> - ret += grub_print_message_indented_real
> -   (_("Press enter to boot the selected OS, "
> -  "`e' to edit the commands before booting "
> -

Re: [PATCH 2/3] osdep/unix/getroot.c: Clean up redundant code

2024-01-25 Thread Vladimir 'phcoder' Serbinenko
Le mar. 23 janv. 2024, 17:44, Daniel Kiper  a écrit :

> Mate,
>
> Next time please respond to all people/addresses in the original
> email...
>
> On Mon, Jan 22, 2024 at 02:09:38PM +, Mate Kukri wrote:
> > Dear Alec, and grub-devel,
> >
> > I haven't checked the specific code in question, but do we really want
> > to be removing such null-assignments? (Thinking about multiple patches
> > exactly like this).
> >
> > In correct code, they are of course redundant by definition, however
> > their intended purpose is that if the code happens to be incorrect,
> > they turn use-after-free bugs into zero page accesses.
> >
> > Since static analysis of a language like C is inherently conservative,
> > it is entirely possible that it is detecting the redundant assignment,
> > but not the use after free it would have prevented.
>
> We know the Coverity makes mistakes. So, we carefully check its reports.
> These ones are not exceptions. Here the Coverity is correct and it is
> safe to remove redundant code. I expect somebody was changing the code
> at some point and forgot to drop surplus assignments.
>
Nope. It was to keep an invariant and ensure we don't double-free
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 0/3] Clean up unused values

2024-01-25 Thread Vladimir 'phcoder' Serbinenko
I oppose to all 3 patches. These assignments are not redundant but keep an
important invariant: the variable in question can be passed to free().
For this it needs to either be NULL or point to a valid allocated memory.
In this code this ensures that we never double free even after code changes

Le sam. 20 janv. 2024, 05:53, Alec Brown  a écrit :

> Coverity listed three unused value bugs in the GRUB. These patches help
> clean
> up and remove these uneccessary bits of code.
>
> The Coverity bugs being addressed are:
> CID 428875
> CID 428876
> CID 428877
>
> Alec Brown (3):
>   fs/jfs.c: Clean up redundant code
>   osdep/unix/getroot.c: Clean up redundant code
>   loader/i386/multiboot_mbi.c: Clean up redundant code
>
>  grub-core/fs/jfs.c| 1 -
>  grub-core/loader/i386/multiboot_mbi.c | 2 +-
>  grub-core/osdep/unix/getroot.c| 1 -
>  3 files changed, 1 insertion(+), 3 deletions(-)
>
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] osdep/hurd/getroot: Fix 64bit build

2024-01-20 Thread Vladimir 'phcoder' Serbinenko
LGTM
Reviewed-by: Vladimir Serbinenko

Le sam. 20 janv. 2024, 21:36, Samuel Thibault 
a écrit :

> file_get_fs_options takes a mach_msg_type_number_t (32bit), not a size_t
> (64bit on 64bit platforms).
> ---
>  grub-core/osdep/hurd/getroot.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/grub-core/osdep/hurd/getroot.c
> b/grub-core/osdep/hurd/getroot.c
> index 0efefdab4..b849700e6 100644
> --- a/grub-core/osdep/hurd/getroot.c
> +++ b/grub-core/osdep/hurd/getroot.c
> @@ -58,7 +58,7 @@ grub_util_find_hurd_root_device (const char *path)
>file_t file;
>error_t err;
>char *argz = NULL, *name = NULL, *ret;
> -  size_t argz_len = 0;
> +  mach_msg_type_number_t argz_len = 0;
>int i;
>
>file = file_name_lookup (path, 0, 0);
> --
> 2.43.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] util/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries

2024-01-17 Thread Vladimir 'phcoder' Serbinenko
Le mer. 17 janv. 2024, 18:10, Pascal Hambourg  a
écrit :

> On 17/01/2024 at 04:15, Vladimir 'phcoder' Serbinenko wrote:
> >>onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
> >>  cat << EOF
> >> +if [ "\$grub_platform" != "efi" ]; then
> >
> > This is not the right check. Only "pc" platform supports chainloadin
> > boot sector. All other: coreboot, qemu, emu, ieee1275, xen and
> > non-x86. The only one which might is xen_pvh but this needs to be
> > checked
>
> I expect os-prober to report boot type "chain" only on platforms which
> support chainloading. Isn't it enough ?

Os-prober has no idea how system is booted. And one of my systems can boot
as any of coreboot, multiboot, EFI, PC or xen. Then I can run qemu version
using whole disk. This together means that the same disk can boot in any
way.

> The goal is to hide "chain" menu
> entries when booting in EFI mode, no more.
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] util/grub.d/30_os-prober.in: Skip drivemap for Windows 8 to 19, Server 2012 and later

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
On Sat, Jan 6, 2024 at 6:38 PM Pascal Hambourg  wrote:
>
> If Windows Vista, Seven and Server 2008 do not need drivemap,
> then later versions using bootmgr too should not need it either.
>
> Note:
> This patch checks Windows versions up to 19 because distinguishing 20
> from 2000 requires more complex logic. Hopefully Windows will drop
> BIOS/legacy boot support before version 20.
Frankly people though x86 would be long dead by now...

> case ${LONGNAME} in
> -   Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
> +   Windows\ Vista*|Windows\ [781]*|Windows\ Server\ 2008*|Windows\ 
> Server\ 20[1-9]*)

What happens to Windows 1.01 ? Or is it detected as MS-DOS?
-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] util/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
>   onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
> cat << EOF
> +if [ "\$grub_platform" != "efi" ]; then

This is not the right check. Only "pc" platform supports chainloadin
boot sector. All other: coreboot, qemu, emu, ieee1275, xen and
non-x86. The only one which might is xen_pvh but this needs to be
checked

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] efi: Fix stack protector issues

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
Looks good. A small comment inline

> diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
> index 731c07c29..5db504e6e 100644
> --- a/grub-core/kern/main.c
> +++ b/grub-core/kern/main.c
> @@ -265,6 +265,11 @@ reclaim_module_space (void)
>  void __attribute__ ((noreturn))
>  grub_main (void)
>  {
> +#ifdef GRUB_STACK_PROTECTOR
> +  /* This call can only be made from a function that does not return. */
Please add a bit of reasoning here not just in the commit message


-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: grub shell: unkown commands alwasy exit with zero code

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
On Tue, Jan 16, 2024 at 11:34 AM Michael Chang via Grub-devel
 wrote:
>
> On Fri, Jan 12, 2024 at 05:58:02PM +0100, Itxaka serrano wrote:
> > Hey all,
> >
> > I opened a bug because this behaviour doesnt seem correct to me:
> >
> > https://savannah.gnu.org/bugs/?65154
> >
> >
> > Example:
> >
> > grub> hello
> > error: ../../grub-core/script/function.c:119:can't find command `hello'.
> > grub> echo $?
> > 0
> >
> >
> > Kind of weird because on the code it seems like its returning a
> > GRUB_ERR_UNKNOWN_COMMAND which should not be zero. I had a quick look and
> > maybe its becuase on line 1018 of grub-core/script/execute.c we print the
> > error but always return 0
> > https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/script/execute.c#n1018
> >
> > Is this expected behaviour or is it a mistake and we should not only print
> > the error but return the actual error?
>
> The behavior is expected:
>
> https://git.savannah.gnu.org/cgit/grub.git/commit/?id=bc028f2f86.
>
$? is set before clearing error so it should be set to unknown
command. So looks like there is more to it.

> Given the limited context, it remains unclear if the rationale behind
> this change can be easily retraced today.
>
> My take is that this modification may have been implemented to support
> the continued functionality of older `grub.cfg` files, even after
> certain commands have been removed. This ensures compatibility with the
> latest version of GRUB. Alternatively, it seems reasonable to halt
> execution when encountering a missing command, considering the potential
> consequence of such situations.
We can have an equivalent of "shopt -e" for those cases. Current
default matches default sh use.

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 08/22] protectors: Add key protectors framework

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
RANGE;
> +
> +  if (protector == NULL || grub_strlen (protector) == 0)
> +return GRUB_ERR_BAD_ARGUMENT;
> +
> +  kp = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors),
> +protector);
> +  if (kp == NULL)
> +return grub_error (GRUB_ERR_OUT_OF_RANGE,
> +  N_("A key protector with name '%s' could not be found. 
> "
> + "Is the name spelled correctly and is the "
> + "corresponding module loaded?"), protector);
> +
> +  return kp->recover_key (key, key_size);
> +}
> diff --git a/include/grub/protector.h b/include/grub/protector.h
> new file mode 100644
> index 0..3d9f69bce
> --- /dev/null
> +++ b/include/grub/protector.h
> @@ -0,0 +1,48 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2022 Microsoft Corporation
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef GRUB_PROTECTOR_HEADER
> +#define GRUB_PROTECTOR_HEADER 1
> +
> +#include 
> +#include 
> +
> +struct grub_key_protector
> +{
> +  struct grub_key_protector *next;
> +  struct grub_key_protector **prev;
> +
> +  const char *name;
> +
> +  grub_err_t (*recover_key) (grub_uint8_t **key, grub_size_t *key_size);
> +};
> +
> +extern struct grub_key_protector *EXPORT_VAR (grub_key_protectors);
> +
> +grub_err_t
> +EXPORT_FUNC (grub_key_protector_register) (struct grub_key_protector 
> *protector);
> +
> +grub_err_t
> +EXPORT_FUNC (grub_key_protector_unregister) (struct grub_key_protector 
> *protector);
> +
> +grub_err_t
> +EXPORT_FUNC (grub_key_protector_recover_key) (const char *protector,
> + grub_uint8_t **key,
> + grub_size_t *key_size);
> +
> +#endif /* ! GRUB_PROTECTOR_HEADER */
> --
> 2.35.3
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 07/22] libtasn1: Add the documentation

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
ar *)b, strlen((const char *)b) + 1)
> +
> + # if SIZEOF_UNSIGNED_LONG_INT == 8
> + #  define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b)
> +diff --git a/grub-core/lib/libtasn1/lib/parser_aux.c 
> b/grub-core/lib/libtasn1/lib/parser_aux.c
> +index c05bd2339..8bdc42ae3 100644
> +--- a/grub-core/lib/libtasn1/lib/parser_aux.c
>  b/grub-core/lib/libtasn1/lib/parser_aux.c
> +@@ -26,7 +26,8 @@
> + #include "gstr.h"
> + #include "structure.h"
> + #include "element.h"
> +-#include "c-ctype.h"
> ++
> ++#define c_isdigit grub_isdigit
> +
> + char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name 
> not found */
> +
> +@@ -40,7 +41,7 @@ char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1];  
>   /* identifier name not fou
> + #ifdef __clang__
> + __attribute__((no_sanitize ("integer")))
> + #endif
> +- _GL_ATTRIBUTE_PURE static unsigned int _asn1_hash_name (const char *x)
> ++ __attribute__((__pure__)) static unsigned int _asn1_hash_name (const 
> char *x)
> + {
> +   const unsigned char *s = (unsigned char *) x;
> +   unsigned h = 0;
> +@@ -632,7 +633,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE])
> +   count = 0;
> +   do
> + {
> +-  d = val / 10;
> ++  d = grub_divmod64(val, 10, NULL);
> +   r = val - d * 10;
> +   temp[start + count] = '0' + (char) r;
> +   count++;
> +diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h
> +index 507e0679e..201089c11 100644
> +--- a/include/grub/libtasn1.h
>  b/include/grub/libtasn1.h
> +@@ -34,29 +34,16 @@
> + #ifndef LIBTASN1_H
> + # define LIBTASN1_H
> +
> +-# ifndef ASN1_API
> +-#  if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
> +-#   define ASN1_API __attribute__((__visibility__("default")))
> +-#  elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
> +-#   define ASN1_API __declspec(dllexport)
> +-#  elif defined _MSC_VER && ! defined ASN1_STATIC
> +-#   define ASN1_API __declspec(dllimport)
> +-#  else
> +-#   define ASN1_API
> +-#  endif
> +-# endif
> ++/* grub: ASN1_API is not used */
> ++# define ASN1_API
> ++
> ++/* grub: all our supported compilers support these attributes */
> ++# define __LIBTASN1_CONST__  __attribute__((const))
> ++# define __LIBTASN1_PURE__  __attribute__((pure))
> +
> +-# ifdef __GNUC__
> +-#  define __LIBTASN1_CONST__  __attribute__((const))
> +-#  define __LIBTASN1_PURE__  __attribute__((pure))
> +-# else
> +-#  define __LIBTASN1_CONST__
> +-#  define __LIBTASN1_PURE__
> +-# endif
> +
> +-# include 
> +-# include 
> +-# include/* for FILE* */
> ++# include 
> ++# include 
> +
> + # ifdef __cplusplus
> + extern "C"
> +--
> +2.35.3
> +
> --
> 2.35.3
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 04/22] libtasn1: changes for grub compatibility

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
On Tue, Jan 16, 2024 at 12:23 PM Gary Lin via Grub-devel
 wrote:
>
> From: Daniel Axtens 
>
> Do a few things to make libtasn1 compile as part of grub:
>
>  - redefine _asn1_strcat. grub removed strcat so replace it with the
>appropriate calls to memcpy and strlen. Use this internally where
>strcat was used.
>
strcat is especially dangerous. If you can't easily replace it with
strncat/strlcat, you probably have a buffer overflow or potential to
have one after some code refactoring.strcpy isn't great either but a
bit better. memcpy+strlen isn't a good replacement. Maybe we can
upstream use of strncat, not based on GRUB needs but based on dangers
of strcat.
>  - replace c_isdigit with grub_isdigit (and don't import c-ctype from
>gnulib) grub_isdigit provides the same functionality as c_isdigit: it
>determines if the input is an ASCII digit without regard for locale.
Can we add c-ctype.h into posix compat?
>
>  - replace GL_ATTRIBUTE_PURE with __attribute__((pure)) which been
>supported since gcc-2.96. This avoids messing around with gnulib.
>
Why not add -DGL_ATTRIBUTE_PURE=... into cppflags? Or even to posix
wrap as long as we're not in gnulib? (e.g. #ifndef GNULIB ... #endif)
>  - adjust libtasn1.h: drop the ASN1_API logic, it's not needed for our
>modules. Unconditionally support const and pure attributes and adjust
>header paths.
Why not -DASN1_API= in cppflags?
const/pure logic seems ok as it was. Did you encounter any problems?>
  if (dest_tot_size > dest_size)
> {
> - strncat (dest, src, (dest_tot_size - dest_size) - 1);
> + memcpy (dest + dest_size, src, (dest_tot_size - dest_size) - 1);

Please add strncat into posix wrap instead. This is a bad change.

-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 05/22] libtasn1: compile into asn1 module

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
LGTM
Reviewed-by: Vladimir Serbinenko 

Le mar. 16 janv. 2024, 12:22, Gary Lin via Grub-devel 
a écrit :

> From: Daniel Axtens 
>
> Create a wrapper file that specifies the module license.
> Set up the makefile so it is built.
>
> Signed-off-by: Daniel Axtens 
> Signed-off-by: Gary Lin 
> ---
>  grub-core/Makefile.core.def| 15 +++
>  grub-core/lib/libtasn1_wrap/wrap.c | 26 ++
>  2 files changed, 41 insertions(+)
>  create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c
>
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 1571421d7..b1294e0f7 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -2595,3 +2595,18 @@ module = {
>efi = commands/bli.c;
>enable = efi;
>  };
> +
> +module = {
> +  name = asn1;
> +  common = lib/libtasn1/lib/decoding.c;
> +  common = lib/libtasn1/lib/coding.c;
> +  common = lib/libtasn1/lib/element.c;
> +  common = lib/libtasn1/lib/structure.c;
> +  common = lib/libtasn1/lib/parser_aux.c;
> +  common = lib/libtasn1/lib/gstr.c;
> +  common = lib/libtasn1/lib/errors.c;
> +  common = lib/libtasn1_wrap/wrap.c;
> +  cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
> +  // -Wno-type-limits comes from libtasn1's configure.ac
> +  cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)
> -I$(srcdir)/lib/libtasn1/lib -Wno-type-limits';
> +};
> diff --git a/grub-core/lib/libtasn1_wrap/wrap.c
> b/grub-core/lib/libtasn1_wrap/wrap.c
> new file mode 100644
> index 0..622ba942e
> --- /dev/null
> +++ b/grub-core/lib/libtasn1_wrap/wrap.c
> @@ -0,0 +1,26 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2020 IBM Corporation
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see .
> + */
> +
> +#include 
> +
> +/*
> + * libtasn1 is provided under LGPL2.1+, which is compatible
> + * with GPL3+. As Grub as a whole is under GPL3+, this module
> + * is therefore under GPL3+ also.
> + */
> +GRUB_MOD_LICENSE ("GPLv3+");
> --
> 2.35.3
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 03/22] libtasn1: disable code not needed in grub

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
I would suggest something a bit more descriptive than if 0. What about
#ifdef GRUB_SKIPPED_IMPORTING ?

Le mar. 16 janv. 2024, 12:24, Gary Lin via Grub-devel 
a écrit :

> From: Daniel Axtens 
>
> We don't expect to be able to write ASN.1, only read it,
> so we can disable some code.
>
> Do that with #if 0/#endif, rather than deletion. This means
> that the difference between upstream and grub is smaller,
> which should make updating libtasn1 easier in the future.
>
> With these exclusions we also avoid the need for minmax.h,
> which is convenient because it means we don't have to
> import it from gnulib.
>
> Signed-off-by: Daniel Axtens 
> Signed-off-by: Gary Lin 
> ---
>  grub-core/lib/libtasn1/lib/coding.c| 12 ++--
>  grub-core/lib/libtasn1/lib/decoding.c  |  2 ++
>  grub-core/lib/libtasn1/lib/element.c   |  4 ++--
>  grub-core/lib/libtasn1/lib/errors.c|  3 +++
>  grub-core/lib/libtasn1/lib/structure.c | 10 ++
>  include/grub/libtasn1.h| 15 +++
>  6 files changed, 38 insertions(+), 8 deletions(-)
>
> diff --git a/grub-core/lib/libtasn1/lib/coding.c
> b/grub-core/lib/libtasn1/lib/coding.c
> index ea5bc370e..841fe47a9 100644
> --- a/grub-core/lib/libtasn1/lib/coding.c
> +++ b/grub-core/lib/libtasn1/lib/coding.c
> @@ -30,11 +30,11 @@
>  #include "parser_aux.h"
>  #include 
>  #include "element.h"
> -#include "minmax.h"
>  #include 
>
>  #define MAX_TAG_LEN 16
>
> +#if 0
>  /**/
>  /* Function : _asn1_error_description_value_not_found */
>  /* Description: creates the ErrorDescription string   */
> @@ -58,6 +58,7 @@ _asn1_error_description_value_not_found (asn1_node node,
>Estrcat (ErrorDescription, "' not found");
>
>  }
> +#endif
>
>  /**
>   * asn1_length_der:
> @@ -244,6 +245,7 @@ asn1_encode_simple_der (unsigned int etype, const
> unsigned char *str,
>return ASN1_SUCCESS;
>  }
>
> +#if 0
>  /**/
>  /* Function : _asn1_time_der  */
>  /* Description: creates the DER coding for a TIME */
> @@ -278,7 +280,7 @@ _asn1_time_der (unsigned char *str, int str_len,
> unsigned char *der,
>
>return ASN1_SUCCESS;
>  }
> -
> +#endif
>
>  /*
>  void
> @@ -519,6 +521,7 @@ asn1_bit_der (const unsigned char *str, int bit_len,
>  }
>
>
> +#if 0
>  /**/
>  /* Function : _asn1_complete_explicit_tag */
>  /* Description: add the length coding to the EXPLICIT */
> @@ -595,6 +598,7 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned
> char *der,
>
>return ASN1_SUCCESS;
>  }
> +#endif
>
>  const tag_and_class_st _asn1_tags[] = {
>[ASN1_ETYPE_GENERALSTRING] =
> @@ -647,6 +651,8 @@ const tag_and_class_st _asn1_tags[] = {
>
>  unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof
> (_asn1_tags[0]);
>
> +
> +#if 0
>  /**/
>  /* Function : _asn1_insert_tag_der*/
>  /* Description: creates the DER coding of tags of one */
> @@ -1423,3 +1429,5 @@ error:
>asn1_delete_structure ();
>return err;
>  }
> +
> +#endif
> \ No newline at end of file
> diff --git a/grub-core/lib/libtasn1/lib/decoding.c
> b/grub-core/lib/libtasn1/lib/decoding.c
> index b9245c486..92fc87c23 100644
> --- a/grub-core/lib/libtasn1/lib/decoding.c
> +++ b/grub-core/lib/libtasn1/lib/decoding.c
> @@ -1620,6 +1620,7 @@ asn1_der_decoding (asn1_node * element, const void
> *ider, int ider_len,
>return asn1_der_decoding2 (element, ider, _len, 0,
> errorDescription);
>  }
>
> +#if 0
>  /**
>   * asn1_der_decoding_element:
>   * @structure: pointer to an ASN1 structure
> @@ -1650,6 +1651,7 @@ asn1_der_decoding_element (asn1_node * structure,
> const char *elementName,
>  {
>return asn1_der_decoding (structure, ider, len, errorDescription);
>  }
> +#endif
>
>  /**
>   * asn1_der_decoding_startEnd:
> diff --git a/grub-core/lib/libtasn1/lib/element.c
> b/grub-core/lib/libtasn1/lib/element.c
> index d4c558e10..5c7941e53 100644
> --- a/grub-core/lib/libtasn1/lib/element.c
> +++ b/grub-core/lib/libtasn1/lib/element.c
> @@ -191,7 +191,7 @@ _asn1_append_sequence_set (asn1_node node, struct
> node_tail_cache_st *pcache)
>return ASN1_SUCCESS;
>  }
>
> -
> +#if 0
>  /**
>   * asn1_write_value:
>   * @node_root: pointer to a structure
> @@ -646,7 +646,7 @@ asn1_write_value (asn1_node node_root, const char
> *name,
>
>return ASN1_SUCCESS;
>  }
> -
> +#endif
>
>  #define PUT_VALUE( ptr, ptr_size, data, data_size) \
> *len = data_size; \
> diff --git a/grub-core/lib/libtasn1/lib/errors.c
> b/grub-core/lib/libtasn1/lib/errors.c
> index aef5dfe6f..0175ddedb 100644
> --- a/grub-core/lib/libtasn1/lib/errors.c
> +++ b/grub-core/lib/libtasn1/lib/errors.c
> @@ -57,6 +57,8 @@ static const libtasn1_error_entry error_algorithms[] = {
>{0, 0}
>  };
>
> +
> +#if 0
>  /**
>   * asn1_perror:
>   * @error: is an error 

Re: [PATCH v8 01/22] posix_wrap: tweaks in preparation for libtasn1

2024-01-16 Thread Vladimir 'phcoder' Serbinenko
LGTM
Reviewed-by: Vladimir Serbinenko 

On Tue, Jan 16, 2024 at 12:22 PM Gary Lin via Grub-devel
 wrote:
>
> From: Daniel Axtens 
>
>  - Define SIZEOF_UNSIGNED_LONG_INT, it's the same as
>SIZEOF_UNSIGNED_LONG.
>
>  - Define WORD_BIT, the size in bits of an int. This is a defined
>in the Single Unix Specification and in gnulib's limits.h. gnulib
>assumes it's 32 bits on all our platforms, including 64 bit
>platforms, so we also use that value.
>
>  - Provide strto[u]l[l] preprocessor macros that resolve to
>grub_strto[u]l[l]. To avoid gcrypt redefining strtoul, we
>also define HAVE_STRTOUL here.
>
> Signed-off-by: Daniel Axtens 
> Signed-off-by: Gary Lin 
> ---
>  grub-core/lib/posix_wrap/limits.h| 1 +
>  grub-core/lib/posix_wrap/stdlib.h| 8 
>  grub-core/lib/posix_wrap/sys/types.h | 1 +
>  3 files changed, 10 insertions(+)
>
> diff --git a/grub-core/lib/posix_wrap/limits.h 
> b/grub-core/lib/posix_wrap/limits.h
> index 26918c8a0..4be7b4080 100644
> --- a/grub-core/lib/posix_wrap/limits.h
> +++ b/grub-core/lib/posix_wrap/limits.h
> @@ -41,5 +41,6 @@
>  #define LONG_MAX GRUB_LONG_MAX
>
>  #define CHAR_BIT 8
> +#define WORD_BIT 32
>
>  #endif
> diff --git a/grub-core/lib/posix_wrap/stdlib.h 
> b/grub-core/lib/posix_wrap/stdlib.h
> index f5279756a..14e4efdd0 100644
> --- a/grub-core/lib/posix_wrap/stdlib.h
> +++ b/grub-core/lib/posix_wrap/stdlib.h
> @@ -64,4 +64,12 @@ abort (void)
>grub_abort ();
>  }
>
> +#define strtol grub_strtol
> +
> +/* for libgcrypt */
> +#define HAVE_STRTOUL
> +#define strtoul grub_strtoul
> +
> +#define strtoull grub_strtoull
> +
>  #endif
> diff --git a/grub-core/lib/posix_wrap/sys/types.h 
> b/grub-core/lib/posix_wrap/sys/types.h
> index eeda543c4..2f3e86549 100644
> --- a/grub-core/lib/posix_wrap/sys/types.h
> +++ b/grub-core/lib/posix_wrap/sys/types.h
> @@ -50,6 +50,7 @@ typedef grub_uint8_t byte;
>  typedef grub_addr_t uintptr_t;
>
>  #define SIZEOF_UNSIGNED_LONG GRUB_CPU_SIZEOF_LONG
> +#define SIZEOF_UNSIGNED_LONG_INT GRUB_CPU_SIZEOF_LONG
>  #define SIZEOF_UNSIGNED_INT 4
>  #define SIZEOF_UNSIGNED_LONG_LONG 8
>  #define SIZEOF_UNSIGNED_SHORT 2
> --
> 2.35.3
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 14/14] mm: Use %x and a case for displaying sizeof.

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
There is some variance in how compiler treat sizeof especially on
32-bit platforms where it can be naturally either int or long.
Explicit cast solves the issue

Signed-off-by: Vladimir Serbinenko 
From 3e738cb99eb15f2cfa9d5c7dc887d2869143a69e Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 13:37:43 +0200
Subject: [PATCH 14/14] mm: Use %x and a case for displaying sizeof.

There is some variance in how compiler treat sizeof especially on
32-bit platforms where it can be naturally either int or long.
Explicit cast solves the issue

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/kern/mm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c
index 792ab0a83..2ba0c184e 100644
--- a/grub-core/kern/mm.c
+++ b/grub-core/kern/mm.c
@@ -238,8 +238,8 @@ grub_mm_init_region (void *addr, grub_size_t size)
*   ||-q->post_size-|size-|
*/
   grub_dprintf ("regions", "Can we extend into region below?"
-" %p + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
-(grub_uint8_t *) q, sizeof(*q), q->size, q->post_size, (grub_uint8_t *) addr);
+" %p + %x + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
+(grub_uint8_t *) q, (int) sizeof(*q), q->size, q->post_size, (grub_uint8_t *) addr);
   if ((grub_uint8_t *) q + sizeof (*q) + q->size + q->post_size ==
 	  (grub_uint8_t *) addr)
 	{
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 13/14] configure: Add RPATH for freetype on NetBSD

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
Without this build-time mkfont fails dynamic linking. This is not ideal
but improves the situation until a better solution is available

Signed-off-by: Vladimir Serbinenko 
From 77daaa1d869c713f674917a90295046a4e3ae8b3 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 01:54:09 +0200
Subject: [PATCH 13/14] configure: Add RPATH for freetype on NetBSD

Without this build-time mkfont fails dynamic linking. This is not ideal
but improves the situation until a better solution is available

Signed-off-by: Vladimir Serbinenko 
---
 configure.ac | 8 
 1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index a35dbdcf2..c1b98b13d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1716,6 +1716,9 @@ if test x"$grub_mkfont_excuse" = x ; then
 CPPFLAGS="$SAVED_CPPFLAGS"
 LIBS="$SAVED_LIBS"
   ], [grub_mkfont_excuse=["need freetype2 library"]])
+  if test x"$grub_mkfont_excuse" = x && test x"$host_kernel" = xnetbsd ; then
+  FREETYPE_LIBS="$FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;
+  fi
 fi
 
 if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
@@ -1770,6 +1773,11 @@ if test x"$grub_build_mkfont_excuse" = x ; then
 LIBS="$SAVED_LIBS"
 CPPFLAGS="$SAVED_CPPFLAGS_2"
   ], [grub_build_mkfont_excuse=["need freetype2 library"]])
+  if test x"$grub_build_mkfont_excuse" = x ; then
+case x"$build_os" in
+  xnetbsd*) BUILD_FREETYPE_LIBS="$BUILD_FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;;
+esac
+  fi
   PKG_CONFIG="$SAVED_PKG_CONFIG"
 fi
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 12/14] Support prefixed nvlist symbol names as found on NetBSD

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
NetBSD uses slightly different function names for the same functions.

Signed-off-by: Vladimir Serbinenko 
From ec4433f62273c16db2b25a19a60492a838aa5178 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 00:01:25 +0200
Subject: [PATCH 12/14] Support prefixed nvlist symbol names as found on NetBSD

NetBSD uses slightly different function names for the same functions.

Signed-off-by: Vladimir Serbinenko 
---
 configure.ac   | 15 +--
 grub-core/osdep/unix/getroot.c |  8 
 include/grub/util/libnvpair.h  | 12 +---
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1fffe996d..a35dbdcf2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1997,8 +1997,19 @@ fi
 
 if test x"$libzfs_excuse" = x ; then
   AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
-   [],
-   [libzfs_excuse="need nvpair library"])
+   [have_normal_nvpair=yes],
+   [have_normal_nvpair=no])
+  if test x"$have_normal_nvpair" = xno ; then
+AC_CHECK_LIB([nvpair], [opensolaris_nvlist_lookup_string],
+ [have_prefixed_nvpair=yes],
+ [have_prefixed_nvpair=no])
+if test x"$have_prefixed_nvpair" = xyes ; then
+  AC_DEFINE([GRUB_UTIL_NVPAIR_IS_PREFIXED], [1],
+[Define to 1 if libnvpair symbols are prefixed with opensolaris_.])
+else
+  libzfs_excuse="need nvpair library"
+fi
+  fi
 fi
 
 if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index 71cdf2e86..ee11b02fb 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -174,20 +174,20 @@ grub_util_find_root_devices_from_poolname (char *poolname)
   zpool = zpool_open (libzfs, poolname);
   config = zpool_get_config (zpool, NULL);
 
-  if (nvlist_lookup_nvlist (config, "vdev_tree", _tree) != 0)
+  if (NVLIST(lookup_nvlist) (config, "vdev_tree", _tree) != 0)
 error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
 
-  if (nvlist_lookup_nvlist_array (vdev_tree, "children", , _count) != 0)
+  if (NVLIST(lookup_nvlist_array) (vdev_tree, "children", , _count) != 0)
 error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
   assert (nvlist_count > 0);
 
-  while (nvlist_lookup_nvlist_array (children[0], "children",
+  while (NVLIST(lookup_nvlist_array) (children[0], "children",
  , _count) == 0)
 assert (nvlist_count > 0);
 
   for (i = 0; i < nvlist_count; i++)
 {
-  if (nvlist_lookup_string (children[i], "path", ) != 0)
+  if (NVLIST(lookup_string) (children[i], "path", ) != 0)
 	error (1, errno, "nvlist_lookup_string (\"path\")");
 
   struct stat st;
diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h
index 573c7ea81..a3acffb88 100644
--- a/include/grub/util/libnvpair.h
+++ b/include/grub/util/libnvpair.h
@@ -29,9 +29,15 @@
 
 typedef void nvlist_t;
 
-int nvlist_lookup_string (nvlist_t *, const char *, char **);
-int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **);
-int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
+#ifdef GRUB_UTIL_NVPAIR_IS_PREFIXED
+#define NVLIST(x) opensolaris_nvlist_ ## x
+#else
+#define NVLIST(x) nvlist_ ## x
+#endif
+
+int NVLIST(lookup_string) (nvlist_t *, const char *, char **);
+int NVLIST(lookup_nvlist) (nvlist_t *, const char *, nvlist_t **);
+int NVLIST(lookup_nvlist_array) (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
 
 #endif /* ! HAVE_LIBNVPAIR_H */
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 11/14] configure: Add *BSD font paths

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
*BSD puts fonts in other places. Add them to the list

Signed-off-by: Vladimir Serbinenko 
From 49c7688352fd815eab6e9fcf214f9e05d9833279 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 00:00:52 +0200
Subject: [PATCH 11/14] configure: Add *BSD font paths

*BSD puts fonts in other places. Add them to the list

Signed-off-by: Vladimir Serbinenko 
---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5e6e7d377..1fffe996d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1817,7 +1817,7 @@ if test "x$with_dejavufont" = x; then
   # search in well-known directories
   if test x"$starfield_excuse" = x; then
  for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
-   for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype; do
+   for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF /usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF; do
   if test -f "$dir/DejaVuSans.$ext"; then
 DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
 break 2
@@ -1846,7 +1846,7 @@ AC_ARG_WITH([unifont],
 if test "x$with_unifont" = x; then
   # search in well-known directories
   for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
-for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc; do
+for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc /usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont /usr/local/share/fonts/unifont; do
   if test -f "$dir/unifont.$ext"; then
 md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
 # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 10/14] autogen: Accept python3.10 as a python alternative

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
NetBSD doesn't provide python or python3

Signed-off-by: Vladimir Serbinenko 


-- 
Regards
Vladimir 'phcoder' Serbinenko
From a07508b0d0de0ff976378c4765f0b613ee4667b1 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 23:25:48 +0200
Subject: [PATCH 10/14] autogen: Accept python3.10 as a python alternative

NetBSD doesn't provide python or python3

Signed-off-by: Vladimir Serbinenko 
---
 autogen.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/autogen.sh b/autogen.sh
index 5a5c356fd..195daa541 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,7 +9,7 @@ fi
 
 # Detect python
 if [ -z "$PYTHON" ]; then
-  for i in python3 python; do
+  for i in python3 python3.10 python; do
 if command -v "$i" > /dev/null 2>&1; then
   PYTHON="$i"
   echo "Using $PYTHON..."
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 09/14] Rename HAVE_LIBZFS to USE_LIBZFS

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
HAVE_LIBZFS is defined by libzfs test and hence conflicts with manual definition
On NetBSD it ends up detecting zfs but not detecting nvpair and creates
confusion
Split them

Signed-off-by: Vladimir Serbinenko 
From 5291725d6f64b590ee90d51d11877cc52d52e733 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 23:24:30 +0200
Subject: [PATCH 09/14] Rename HAVE_LIBZFS to USE_LIBZFS

HAVE_LIBZFS is defined by libzfs test and hence conflicts with manual definition
On NetBSD it ends up detecting zfs but not detecting nvpair and creates
confusion
Split them

Signed-off-by: Vladimir Serbinenko 
---
 configure.ac   | 6 ++
 grub-core/osdep/unix/getroot.c | 4 ++--
 util/getroot.c | 6 +++---
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index c19779c14..5e6e7d377 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2008,11 +2008,9 @@ fi
 if test x"$libzfs_excuse" = x ; then
   # We need both libzfs and libnvpair for a successful build.
   LIBZFS="-lzfs"
-  AC_DEFINE([HAVE_LIBZFS], [1],
-[Define to 1 if you have the ZFS library.])
   LIBNVPAIR="-lnvpair"
-  AC_DEFINE([HAVE_LIBNVPAIR], [1],
-[Define to 1 if you have the NVPAIR library.])
+  AC_DEFINE([USE_LIBZFS], [1],
+[Define to 1 if ZFS library should be used.])
 fi
 
 AC_SUBST([LIBZFS])
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index cde821eb9..71cdf2e86 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -53,7 +53,7 @@
 
 #include 
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
 # include 
 # include 
 #endif
@@ -158,7 +158,7 @@ grub_util_find_root_devices_from_poolname (char *poolname)
   size_t ndevices = 0;
   size_t devices_allocated = 0;
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
   zpool_handle_t *zpool;
   libzfs_handle_t *libzfs;
   nvlist_t *config, *vdev_tree;
diff --git a/util/getroot.c b/util/getroot.c
index 086581998..75a7d5f21 100644
--- a/util/getroot.c
+++ b/util/getroot.c
@@ -47,7 +47,7 @@
 
 #include 
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
 # include 
 # include 
 #endif
@@ -456,7 +456,7 @@ grub_util_biosdisk_is_present (const char *os_dev)
   return ret;
 }
 
-#ifdef HAVE_LIBZFS
+#ifdef USE_LIBZFS
 static libzfs_handle_t *__libzfs_handle;
 
 static void
@@ -478,5 +478,5 @@ grub_get_libzfs_handle (void)
 
   return __libzfs_handle;
 }
-#endif /* HAVE_LIBZFS */
+#endif /* USE_LIBZFS */
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 08/14] gnulib: Tolerate always_inline attribute being ignored.

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
It's not critical, Werror on it is inappropriate. We don't want to modify gnulib
too much. This warning is pretty much irrelevant.

Signed-off-by: Vladimir Serbinenko 
From 8aca438ea92fa0cae827c026678fbc55b5613d80 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 22:45:53 +0200
Subject: [PATCH 08/14] gnulib: Tolerate always_inline attribute being ignored.

It's not critical, Werror on it is inappropriate. We don't want to modify gnulib
too much. This warning is pretty much irrelevant.

Signed-off-by: Vladimir Serbinenko 
---
 conf/Makefile.common | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/conf/Makefile.common b/conf/Makefile.common
index f8faa92e9..b8f216f6c 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -75,7 +75,7 @@ grubconfdir = $(sysconfdir)/grub.d
 platformdir = $(pkglibdir)/$(target_cpu)-$(platform)
 starfielddir = $(pkgdatadir)/themes/starfield
 
-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion
+CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-error=attributes
 CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib
 
 CFLAGS_POSIX = -fno-builtin
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 07/14] Don't use %m formatter

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
It's not available on NetBSD outside of syslog. Using strerror is more reliable
as we retrieve errno immediately rather than down the stack

Signed-off-by: Vladimir Serbinenko 


-- 
Regards
Vladimir 'phcoder' Serbinenko
From c8990bda2de54cf87de65835436ba0b2182b0e5c Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 22:32:45 +0200
Subject: [PATCH 07/14] Don't use %m formatter

It's not available on NetBSD outside of syslog. Using strerror is more reliable
as we retrieve errno immediately rather than down the stack

Signed-off-by: Vladimir Serbinenko 
---
 util/editenv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/editenv.c b/util/editenv.c
index c532b046f..9cafd838d 100644
--- a/util/editenv.c
+++ b/util/editenv.c
@@ -91,7 +91,7 @@ grub_util_create_envblk_file (const char *name)
   else if (retsize < 0)
 {
   free (linkbuf);
-  grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name);
+  grub_util_error (_("cannot rename the file %s to %s: %s"), namenew, name, strerror(errno));
 }
   else if (retsize == size)
 {
@@ -128,7 +128,7 @@ grub_util_create_envblk_file (const char *name)
   free (rename_target);
 
   if (rc < 0)
-grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name);
+grub_util_error (_("cannot rename the file %s to %s: %s"), namenew, name, strerror(errno));
 #endif
 
   free (namenew);
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 06/14] bsd/hostdisk: Fix NetBSD compilation

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
Wrong function and variable name cause a stupid compilation error on NetBSD
and OpenBSD. Only NetBSD and OpenBSD use this file. No other platform is
affected

Signed-off-by: Vladimir Serbinenko 
From abfb6d28342de26ce3e750f3a5a477221efcdc62 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 21:48:20 +0200
Subject: [PATCH 06/14] bsd/hostdisk: Fix NetBSD compilation

Wrong function and variable name cause a stupid compilation error on NetBSD
and OpenBSD. Only NetBSD and OpenBSD use this file. No other platform is
affected

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/osdep/bsd/hostdisk.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/grub-core/osdep/bsd/hostdisk.c b/grub-core/osdep/bsd/hostdisk.c
index 891109462..1a7ea97b4 100644
--- a/grub-core/osdep/bsd/hostdisk.c
+++ b/grub-core/osdep/bsd/hostdisk.c
@@ -56,6 +56,10 @@
 # endif
 
 #if defined(__NetBSD__)
+# ifndef RAW_FLOPPY_MAJOR
+#  define RAW_FLOPPY_MAJOR	9
+# endif /* ! RAW_FLOPPY_MAJOR */
+
 /* Adjust device driver parameters.  This function should be called just
after successfully opening the device.  For now, it simply prevents the
floppy driver from retrying operations on failure, as otherwise the
@@ -92,7 +96,7 @@ grub_util_fd_open (const char *os_dev, int flags)
 
   ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
   if (ret >= 0)
-configure_device_driver (fd);
+configure_device_driver (ret);
   return ret;
 }
 
@@ -105,7 +109,7 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
   unsigned sector_size, log_sector_size;
 
 #if defined(__NetBSD__)
-  grub_hostdisk_configure_device_driver (fd);
+  configure_device_driver (fd);
 #endif
 
   if (ioctl (fd, DIOCGDINFO, ) == -1)
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 05/14] bootstrap: Don't check gettext version

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
NetBSD gettext is older than the check but we don't actually need 0.18.3,
older works fine.

This is needed to make bootstrap work on NetBSD

Signed-off-by: Vladimir Serbinenko 
From 42fd822c4606ccd13c8b4ac58b3b07dbee55d7da Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 21:47:50 +0200
Subject: [PATCH 05/14] bootstrap: Don't check gettext version

NetBSD gettext is older than the check but we don't actually need 0.18.3,
older works fine.

This is needed to make bootstrap work on NetBSD

Signed-off-by: Vladimir Serbinenko 
---
 bootstrap.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 64ea9bcb5..7a7813d28 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -68,7 +68,7 @@ SKIP_PO=t
 buildreq="\
 autoconf   2.64
 automake   1.14
-gettext0.18.3
+gettext-
 git1.5.5
 patch  -
 tar-
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 04/14] Fix compilation of generic/blocklist

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
After recent change in blocklist types we have a type mismatch. Fixing it
requires a wrapper or large changes. I feel like wrapper makes more sense

Without this patch we end up with a compilation problem and without wrapping
callback data is not passed properly anymore

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/osdep/generic/blocklist.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)
From e8ed2571c4215ac8cbc56b8524d6d363485c8c1f Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 09:33:47 +0200
Subject: [PATCH 04/14] Fix compilation of generic/blocklist

After recent change in blocklist types we have a type mismatch. Fixing it
requires a wrapper or large changes. I feel like wrapper makes more sense

Without this patch we end up with a compilation problem and without wrapping
callback data is not passed properly anymore

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/osdep/generic/blocklist.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/grub-core/osdep/generic/blocklist.c b/grub-core/osdep/generic/blocklist.c
index 2d9040302..97e416866 100644
--- a/grub-core/osdep/generic/blocklist.c
+++ b/grub-core/osdep/generic/blocklist.c
@@ -30,6 +30,25 @@
 
 #define MAX_TRIES	5
 
+struct wrapper_hook_data
+{
+  void (*callback) (grub_disk_addr_t sector,
+		unsigned offset,
+		unsigned length,
+		void *data);
+  void *callback_data;
+};
+
+static grub_err_t
+callback_wrapper (grub_disk_addr_t sector,
+		  unsigned offset, unsigned length,
+		  char *buf, void *data)
+{
+  struct wrapper_hook_data *wrap = data;
+  wrap->callback(sector, offset, length, wrap->callback_data);
+  return GRUB_ERR_NONE;
+}
+
 void
 grub_install_get_blocklist (grub_device_t root_dev,
 			const char *core_path, const char *core_img,
@@ -43,6 +62,10 @@ grub_install_get_blocklist (grub_device_t root_dev,
   int i;
   char *tmp_img;
   char *core_path_dev;
+  struct wrapper_hook_data wrap_hook_data = {
+.callback = callback,
+.callback_data = hook_data
+  };
 
   core_path_dev = grub_make_system_path_relative_to_its_root (core_path);
 
@@ -120,8 +143,8 @@ grub_install_get_blocklist (grub_device_t root_dev,
   if (! file)
 grub_util_error ("%s", grub_errmsg);
 
-  file->read_hook = callback;
-  file->read_hook_data = hook_data;
+  file->read_hook = callback_wrapper;
+  file->read_hook_data = _hook_data;
   if (grub_file_read (file, tmp_img, core_size) != (grub_ssize_t) core_size)
 grub_util_error ("%s", _("failed to read the sectors of the core image"));
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 03/14] diskfilter: Remove unused variable

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
Variable e is set but never used. We can just remove it now.

Signed-off-by: Vladimir Serbinenko 
From 2c24c247d81de30aa28e671da1ac6a7587c2f54e Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 02:32:55 +0200
Subject: [PATCH 03/14] diskfilter: Remove unused variable

Variable e is set but never used. We can just remove it now.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/disk/diskfilter.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
index 61a311efd..21e239511 100644
--- a/grub-core/disk/diskfilter.c
+++ b/grub-core/disk/diskfilter.c
@@ -720,7 +720,7 @@ read_segment (struct grub_diskfilter_segment *seg, grub_disk_addr_t sector,
 case GRUB_DISKFILTER_RAID6:
   {
 	grub_disk_addr_t read_sector;
-	grub_uint64_t b, p, n, disknr, e;
+	grub_uint64_t b, p, n, disknr;
 
 	/* n = 1 for level 4 and 5, 2 for level 6.  */
 	n = seg->type / 3;
@@ -770,7 +770,6 @@ read_segment (struct grub_diskfilter_segment *seg, grub_disk_addr_t sector,
 	if (read_size > size)
 	  read_size = size;
 
-	e = 0;
 	/* Reset read error.  */
 	if (grub_errno == GRUB_ERR_READ_ERROR
 		|| grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
@@ -784,7 +783,6 @@ read_segment (struct grub_diskfilter_segment *seg, grub_disk_addr_t sector,
 	if ((err) && (err != GRUB_ERR_READ_ERROR
 			  && err != GRUB_ERR_UNKNOWN_DEVICE))
 	  return err;
-	e++;
 
 	if (err)
 	  {
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 02/14] Tolerate unused-but-set in generated lexer/bison files

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
We don't really control the small aspects of generated files and NetBSD
version has an unused variable that is then detected by gcc as warning that
is then promoted to error.

Signed-off-by: Vladimir Serbinenko 
From 2c05ed1ac720f99f94387dbb40558e7f3551e9ae Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 02:32:26 +0200
Subject: [PATCH 02/14] Tolerate unused-but-set in generated lexer/bison files

We don't really control the small aspects of generated files and NetBSD
version has an unused variable that is then detected by gcc as warning that
is then promoted to error.

Signed-off-by: Vladimir Serbinenko 
---
 Makefile.util.def   | 2 +-
 grub-core/Makefile.core.def | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.util.def b/Makefile.util.def
index 6fe08efd8..9432365a9 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -55,7 +55,7 @@ library = {
 
 library = {
   name = libgrubmods.a;
-  cflags = '-fno-builtin -Wno-undef';
+  cflags = '-fno-builtin -Wno-undef -Wno-unused-but-set-variable';
   cppflags = '-I$(srcdir)/grub-core/lib/minilzo -I$(srcdir)/grub-core/lib/xzembed -I$(srcdir)/grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H';
 
   common_nodist = grub_script.tab.c;
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index d2cf29584..1571421d7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1993,7 +1993,7 @@ module = {
   extra_dist = script/yylex.l;
   extra_dist = script/parser.y;
 
-  cflags = '$(CFLAGS_POSIX) -Wno-redundant-decls';
+  cflags = '$(CFLAGS_POSIX) -Wno-redundant-decls -Wno-unused-but-set-variable';
   cppflags = '$(CPPFLAGS_POSIX)';
 };
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 01/14] loader/bsd: Fix loading after unaligned module

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
Current code implicitly assumes that aligning chunk_size + *kern_end is
the same as aligning on curload which is not the case because
chunk_size starts at zero even if *kern_end is unaligned and ALIGN_PAGE
moved curload to an aligned position but not *kern_end + chunk_size

This fixes booting of FreeBSD with zfs module.

Signed-off-by: Vladimir Serbinenko 
From 6363af27854bcfc7740ef3bdee5707111d5d19a9 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Mon, 10 Jul 2023 17:17:35 +0200
Subject: [PATCH 01/14] loader/bsd: Fix loading after unaligned module

Current code implicitly assumes that aligning chunk_size + *kern_end is
the same as aligning on curload which is not the case because
chunk_size starts at zero even if *kern_end is unaligned and ALIGN_PAGE
moved curload to an aligned position but not *kern_end + chunk_size

This fixes booting of FreeBSD with zfs module.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/loader/i386/bsdXX.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c
index 09d909f1b..d3de8a29b 100644
--- a/grub-core/loader/i386/bsdXX.c
+++ b/grub-core/loader/i386/bsdXX.c
@@ -88,10 +88,9 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
   Elf_Shnum shnum;
   grub_addr_t curload, module;
   grub_err_t err;
-  grub_size_t chunk_size = 0;
   void *chunk_src;
 
-  curload = module = ALIGN_PAGE (*kern_end);
+  module = ALIGN_PAGE (*kern_end);
 
   err = read_headers (file, argv[0], , );
   if (err != GRUB_ERR_NONE)
@@ -101,6 +100,8 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
   if (err != GRUB_ERR_NONE)
 goto out;
 
+  curload = module;
+
   for (s = shdr; s < (Elf_Shdr *) ((grub_uint8_t *) shdr + shnum * e.e_shentsize);
s = (Elf_Shdr *) ((grub_uint8_t *) s + e.e_shentsize))
 {
@@ -108,21 +109,24 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
 	continue;
 
   if (s->sh_addralign)
-	chunk_size = ALIGN_UP (chunk_size + *kern_end, s->sh_addralign)
-	  - *kern_end;
+	curload = ALIGN_UP (curload, s->sh_addralign);
 
-  chunk_size += s->sh_size;
+  curload += s->sh_size;
 }
 
+  *kern_end = ALIGN_PAGE (curload);
+
   {
 grub_relocator_chunk_t ch;
 err = grub_relocator_alloc_chunk_addr (relocator, ,
-	   module, chunk_size);
+	   module, curload - module);
 if (err != GRUB_ERR_NONE)
   goto out;
 chunk_src = get_virtual_current_address (ch);
   }
 
+  curload = module;
+
   for (s = shdr; s < (Elf_Shdr *) ((grub_uint8_t *) shdr + shnum * e.e_shentsize);
s = (Elf_Shdr *) ((grub_uint8_t *) s + e.e_shentsize))
 {
@@ -141,13 +145,13 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
 	{
 	default:
 	case SHT_PROGBITS:
-	  err = load (file, argv[0], (grub_uint8_t *) chunk_src + curload - *kern_end,
+	  err = load (file, argv[0], (grub_uint8_t *) chunk_src + curload - module,
 		  s->sh_offset, s->sh_size);
 	  if (err != GRUB_ERR_NONE)
 	goto out;
 	  break;
 	case SHT_NOBITS:
-	  grub_memset ((grub_uint8_t *) chunk_src + curload - *kern_end, 0,
+	  grub_memset ((grub_uint8_t *) chunk_src + curload - module, 0,
 		   s->sh_size);
 	  break;
 	}
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 00/14] Fix compilation on *BSD platforms

2023-12-10 Thread Vladimir 'phcoder' Serbinenko
This patch series fixes compilation problems and one boot bug for different
BSD platforms. Mostly they are safe and touch files which are not used by
Linux
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 0/2] Bli: fix hidden module dependency

2023-11-14 Thread Vladimir 'phcoder' Serbinenko
In general series looks good. Few comments:
* I'm unsure about the name. It seems to suggest that people put the
dependencies there by default while in fact it's the last place for it.
Maybe extra_deps.lst?
* EFI supports both GPT and msdos. GPT is a more common choice but I still
think that a dependency on part_msdos is warranted
* Please elaborate commit message as to why bli needs those mods rather
than "not functions properly". Detail that it needs to identify partitions.


Le mar. 14 nov. 2023, 17:45, Oliver Steffen  a écrit :

> The bli module has a hidden/implicit dependency on the part_gpt module.
> The part_gpt module has to be loaded before the bli module.
> This dependency is not picked up automatically by the build system
> because the bli module does not use any function of part_gpt. It just
> expects Grub to be able to parse GPT formatted disks.
>
> This series introduces a mechanism that allows specifying module
> dependencies explicitly in a new file called explicit_dependencies.lst.
>
> An explicit dependency is then added for the bli module on the part_gpt
> module.
>
> Oliver Steffen (2):
>   Allow explicit module dependencies
>   bli: Add explicit dependency on the part_gpt module
>
>  grub-core/Makefile.am   | 4 ++--
>  grub-core/explicit_dependencies.lst | 1 +
>  grub-core/genmoddep.awk | 4 
>  3 files changed, 7 insertions(+), 2 deletions(-)
>  create mode 100644 grub-core/explicit_dependencies.lst
>
> --
> 2.41.0
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 3/4] types: Split aligned and packed guids

2023-11-06 Thread Vladimir 'phcoder' Serbinenko
> These casts looks strange for me. Could not we change the functions
> declarations in the grub_efi_runtime_services? If not I think this
> change should be explained in the commit message.

New commit message:

types: Split aligned and packed guids

On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types

The code is structured in a way to accept unaligned inputs
in most cases and supply 4-byte aligned outputs.

Efiemu case is a bit ugly because there inputs and outputs are
reversed and so we need careful casts to account for this
inversion.

Signed-off-by: Vladimir Serbinenko 



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] acpi: Mark MADT entries as packed.

2023-11-06 Thread Vladimir 'phcoder' Serbinenko
Le lun. 6 nov. 2023, 18:04, Daniel Kiper  a écrit :

> On Tue, Oct 31, 2023 at 08:20:14PM +0100, Vladimir 'phcoder' Serbinenko
> wrote:
> > From 9d03ab04df3b723058fb0b7c30576e1330cbad5d Mon Sep 17 00:00:00 2001
> > From: Vladimir Serbinenko 
> > Date: Tue, 31 Oct 2023 18:27:19 +0100
> > Subject: [PATCH] acpi: Mark MADT entries as packed.
> >
> > No alignment is guaranteed and in fact on my ia64 sapic is aligned
> > to 4 bytes instead of 8 and causes a trap. It affects only rarely used
> > lsacpi command and so went unnoticed.
>
> At least you missed grub_acpi_madt_entry_header struct. It should have
> packed attribute too.
>
Nope. It has only uint8. So no need for packed

>
> Daniel
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v3] ieee1275/ofdisk: retry on open and read failure

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
> +{
> +  err = grub_ofdisk_open_real (name, disk);
> +  cont = grub_get_time_ms () < timeout;
> +  if (err == GRUB_ERR_UNKNOWN_DEVICE && cont)
> +{
> +  grub_dprintf ("ofdisk","Failed to open disk %s. Retrying...\n", 
> name);
> +  grub_errno = GRUB_ERR_NONE;
> +}
> +  else
> +  break;
> +  grub_millisleep (1000);

Can you make this exponentially increasing and add a random number.
Something like:
(32 << try) * (32 + random_between(-16, +16))

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] gzio: Avoid spurious failures

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
On Tue, Oct 31, 2023 at 7:28 PM Jason Andryuk  wrote:
>
> grub_gzio_read_real() uses grub_errno to identify decompression failures
> when the function completes.  Its callees in gzio.c are void-returning
> functions that set grub_errno on their exit paths.
>
> A Fedora 38 machine was observed to fail `multiboot2 /xen.gz` with
> "premature end of file".  xen.gz was well formed and could be
> successfully gunzip-ed in Linux.
>
> The TPM is flaky and produces errors when the verifier tries to extend
> PCRs with measurements.  Logs show "Unkown TPM error" and grub_errno is
> set to GRUB_ERR_UNKNOWN_DEVICE.  This pre-existing grub_errno causes an
> otherwise successful grub_gzio_read_real() call to return error.
This bus is likely to create other problems as well. Why not fix it?
If this error is meant to be ignored rather than stop loading, then it
should be discarded early, possibly printed. If it should stop loading
then this should really stop and not even get here
>
> Add a grub_debug_errno() macro to print existing grub_errno messages at
> the start of the function, and reset grub_errno to avoid such errors.
>
> Signed-off-by: Jason Andryuk 
> ---
> v2:
> Add grub_debug_errno helper
> Separate debug from reset.
> ---
>  grub-core/io/gzio.c | 4 
>  include/grub/err.h  | 9 +
>  2 files changed, 13 insertions(+)
>
> diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
> index ca9355751..883df0011 100644
> --- a/grub-core/io/gzio.c
> +++ b/grub-core/io/gzio.c
> @@ -1294,6 +1294,10 @@ grub_gzio_read_real (grub_gzio_t gzio, grub_off_t 
> offset,
>  {
>grub_ssize_t ret = 0;
>
> +  /* Avoid spurious failures on exit when grub_errno is already set. */
> +  grub_debug_errno();
> +  grub_errno = GRUB_ERR_NONE;
> +
>/* Do we reset decompression to the beginning of the file?  */
>if (gzio->saved_offset > offset + WSIZE)
>  initialize_tables (gzio);
> diff --git a/include/grub/err.h b/include/grub/err.h
> index 1c07034cd..f6948ecf8 100644
> --- a/include/grub/err.h
> +++ b/include/grub/err.h
> @@ -96,4 +96,13 @@ extern int EXPORT_VAR(grub_err_printed_errors);
>  int grub_err_printf (const char *fmt, ...)
>   __attribute__ ((format (GNU_PRINTF, 1, 2)));
>
> +#define grub_debug_errno() \
> +do { \
> +  if ( grub_errno != GRUB_ERR_NONE ) \
> +{ \
> +  grub_dprintf ("errno", "%s: clearing pre-exising errmsg %s\n", \
> +__func__, grub_errmsg); \
> +} \
> +} while (0);
> +
>  #endif /* ! GRUB_ERR_HEADER */
> --
> 2.41.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 0/4] Fix GUID alignment on ia64

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
Fix GUID alignment problems encountered on ia64. Tested on zx2000 workstation

-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 4/4] gpt: Add compile time asserts for guid and gpt_partentry sizes

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
With new alignment specification it's easy to screw up. Fortunately if it
happens the size will be bigger than intended. Compile time assert will catch
this.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko
From 6a4e58a9fe989dbe0f6b3ef9865cab05a55ac19a Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:18:53 +0200
Subject: [PATCH 4/4] gpt: Add compile time asserts for guid and gpt_partentry
 sizes

With new alignment specification it's easy to screw up. Fortunately if it
happens the size will be bigger than intended. Compile time assert will catch
this.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/partmap/gpt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
index 877ceefc3..426f616ae 100644
--- a/grub-core/partmap/gpt.c
+++ b/grub-core/partmap/gpt.c
@@ -229,6 +229,9 @@ static struct grub_partition_map grub_gpt_partition_map =
 
 GRUB_MOD_INIT(part_gpt)
 {
+  COMPILE_TIME_ASSERT(sizeof(grub_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(grub_packed_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(struct grub_gpt_partentry) == 128);
   grub_partition_map_register (_gpt_partition_map);
 }
 
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 3/4] types: Split aligned and packed guids

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko
From 48c239ad9efc40563015052383d80830d410c2c8 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:18:23 +0200
Subject: [PATCH 3/4] types: Split aligned and packed guids

On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/commands/efi/lsefi.c|  2 +-
 grub-core/efiemu/runtime/efiemu.c | 33 +--
 grub-core/kern/efi/efi.c  |  2 +-
 grub-core/kern/misc.c |  2 +-
 grub-core/loader/i386/xnu.c   |  2 +-
 include/grub/efi/api.h| 12 +--
 include/grub/efiemu/efiemu.h  |  4 ++--
 include/grub/efiemu/runtime.h |  2 +-
 include/grub/types.h  | 11 ++-
 9 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c
index 95cba5baf..7b8316d41 100644
--- a/grub-core/commands/efi/lsefi.c
+++ b/grub-core/commands/efi/lsefi.c
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
   grub_efi_handle_t handle = handles[i];
   grub_efi_status_t status;
   grub_efi_uintn_t num_protocols;
-  grub_guid_t **protocols;
+  grub_packed_guid_t **protocols;
   grub_efi_device_path_t *dp;
 
   grub_printf ("Handle %p\n", handle);
diff --git a/grub-core/efiemu/runtime/efiemu.c b/grub-core/efiemu/runtime/efiemu.c
index c84b30652..f6b6d19f7 100644
--- a/grub-core/efiemu/runtime/efiemu.c
+++ b/grub-core/efiemu/runtime/efiemu.c
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-		 const grub_guid_t *vendor_guid,
+		 const grub_packed_guid_t *vendor_guid,
 		 grub_efi_uint32_t *attributes,
 		 grub_efi_uintn_t *data_size,
 		 void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
 			   grub_efi_char16_t *variable_name,
-			   grub_guid_t *vendor_guid);
+			   grub_packed_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-		 const grub_guid_t *vendor_guid,
+		 const grub_packed_guid_t *vendor_guid,
 		 grub_efi_uint32_t attributes,
 		 grub_efi_uintn_t data_size,
 		 void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_guid_t *vendor_guid,
+find_variable (const grub_packed_guid_t *vendor_guid,
 	   grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-const grub_guid_t *vendor_guid,
+const grub_packed_guid_t *vendor_guid,
 grub_efi_uint32_t *attributes,
 grub_efi_uintn_t *data_size,
 void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
  grub_efi_char16_t *variable_name,
- grub_guid_t *vendor_guid)
+ grub_packed_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-const grub_guid_t *vendor_guid,
+const grub_packed_guid_t *vendor_guid,
 grub_efi_uint32_t attributes,
 grub_efi_uintn_t data_size,
 void *data)
@@ -597,9 +597,22 @@ struct grub_efi_runtime_services efiemu_runtime_services =
   .set_virtual_address_map = efiemu_set_virtual_address_map,
   .convert_pointer = efiemu_convert_pointer,
 
-  .get_variable = efiemu_get_variable,
-  .get_next_variable_name = efiemu_get_next_variable_name,
-  .set_variable = efiemu_set_variable,
+  .get_variable = (grub_efi_status_t
+		   (__grub_efi_api *) (grub_efi_char16_t *variable_name,
+   const grub_guid_t *vendor_guid,
+   grub_efi_uint32_t *attributes,
+   grub_efi_uintn_t *data_size,
+   void *data)) efiemu_ge

[PATCH 2/4] gpt_partition: Mark grub_gpt_partentry as having natural alignment

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
gpt_partition contains grub_guid. We need to decide whether the whole
structure is unaligned and then we need to use packed_guid. But we never
have unaligned part entries as we read them in an aligned buffer from disk.
Hence just make it all aligned.

Signed-off-by: Vladimir Serbinenko 

-- 
Regards
Vladimir 'phcoder' Serbinenko
From 1c804f57fe25f1fbea7a933eec99fe1e20a23065 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Tue, 31 Oct 2023 18:24:09 +0100
Subject: [PATCH 2/4] gpt_partition: Mark grub_gpt_partentry as having natural
 alignment

gpt_partition contains grub_guid. We need to decide whether the whole
structure is unaligned and then we need to use packed_guid. But we never
have unaligned part entries as we read them in an aligned buffer from disk.
Hence just make it all aligned.

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/gpt_partition.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
index 020e71920..292ea03f1 100644
--- a/include/grub/gpt_partition.h
+++ b/include/grub/gpt_partition.h
@@ -67,7 +67,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} GRUB_PACKED;
+};
 
 grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 1/4] efi: Deduplicate configuration table search function

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
We do table search in many places doing exactly the same algorithm.
The only minor variance in users is which table is used if several entries
are present. As specification mandates uniqueness and even if it ever isn't,
first entry is good enough, unify this code and always use the first entry.

-- 
Regards
Vladimir 'phcoder' Serbinenko
From ef8f6f068b275e3c010d3793048ac1d702d3f0fa Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:15:02 +0200
Subject: [PATCH 1/4] efi: Deduplicate configuration table search function

We do table search in many places doing exactly the same algorithm.
The only minor variance in users is which table is used if several entries
are present. As specification mandates uniqueness and even if it ever isn't,
first entry is good enough, unify this code and always use the first entry.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/commands/efi/loadbios.c | 37 ---
 grub-core/commands/efi/lssal.c| 18 +--
 grub-core/commands/efi/smbios.c   | 28 ++-
 grub-core/kern/efi/acpi.c | 26 ++
 grub-core/kern/efi/efi.c  | 18 +++
 grub-core/kern/efi/fdt.c  | 20 +
 include/grub/efi/efi.h|  3 +++
 7 files changed, 46 insertions(+), 104 deletions(-)

diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c
index 8f6b0ecfc..8e042095a 100644
--- a/grub-core/commands/efi/loadbios.c
+++ b/grub-core/commands/efi/loadbios.c
@@ -92,7 +92,6 @@ lock_rom_area (void)
 static void
 fake_bios_data (int use_rom)
 {
-  unsigned i;
   void *acpi, *smbios;
   grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
 
@@ -101,33 +100,15 @@ fake_bios_data (int use_rom)
   if ((*ebda_seg_ptr) || (*low_mem_ptr))
 return;
 
-  acpi = 0;
-  smbios = 0;
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-{
-  grub_guid_t *guid =
-	_efi_system_table->configuration_table[i].vendor_guid;
-
-  if (! grub_memcmp (guid, _guid, sizeof (grub_guid_t)))
-	{
-	  acpi = grub_efi_system_table->configuration_table[i].vendor_table;
-	  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
-	}
-  else if (! grub_memcmp (guid, _guid, sizeof (grub_guid_t)))
-	{
-	  void *t;
-
-	  t = grub_efi_system_table->configuration_table[i].vendor_table;
-	  if (! acpi)
-	acpi = t;
-	  grub_dprintf ("efi", "ACPI: %p\n", t);
-	}
-  else if (! grub_memcmp (guid, _guid, sizeof (grub_guid_t)))
-	{
-	  smbios = grub_efi_system_table->configuration_table[i].vendor_table;
-	  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
-	}
-}
+  acpi = grub_efi_find_configuration_table (_guid);
+  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
+  if (!acpi) {
+acpi = grub_efi_find_configuration_table (_guid);
+grub_dprintf ("efi", "ACPI: %p\n", acpi);
+  }
+
+  smbios = grub_efi_find_configuration_table (_guid);
+  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
 
   *ebda_seg_ptr = FAKE_EBDA_SEG;
   *low_mem_ptr = (FAKE_EBDA_SEG >> 6);
diff --git a/grub-core/commands/efi/lssal.c b/grub-core/commands/efi/lssal.c
index fd6085f1b..7248bdc29 100644
--- a/grub-core/commands/efi/lssal.c
+++ b/grub-core/commands/efi/lssal.c
@@ -136,22 +136,16 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
 		int argc __attribute__ ((unused)),
 		char **args __attribute__ ((unused)))
 {
-  const grub_efi_system_table_t *st = grub_efi_system_table;
-  grub_efi_configuration_table_t *t = st->configuration_table;
-  unsigned int i;
   static grub_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
+  void *table = grub_efi_find_configuration_table ();
 
-  for (i = 0; i < st->num_table_entries; i++)
+  if (table == NULL)
 {
-  if (grub_memcmp (, >vendor_guid,
-		   sizeof (grub_guid_t)) == 0)
-	{
-	  disp_sal (t->vendor_table);
-	  return GRUB_ERR_NONE;
-	}
-  t++;
+  grub_printf ("SAL not found\n");
+  return GRUB_ERR_NONE;
 }
-  grub_printf ("SAL not found\n");
+
+  disp_sal (table);
   return GRUB_ERR_NONE;
 }
 
diff --git a/grub-core/commands/efi/smbios.c b/grub-core/commands/efi/smbios.c
index d77239732..717e5fc1d 100644
--- a/grub-core/commands/efi/smbios.c
+++ b/grub-core/commands/efi/smbios.c
@@ -18,44 +18,20 @@
  */
 
 #include 
-#include 
 #include 
-#include 
 
 struct grub_smbios_eps *
 grub_machine_smbios_get_eps (void)
 {
-  unsigned i;
   static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-{
-  grub_guid_t *guid =
-	_efi_system_table->configuration_table[i].vendor_guid;
-
-  if (! grub_memcmp (guid, _guid, sizeof (grub_guid_t)))
-	return (struct grub_smbios_eps *)
-	  grub_efi_system_table->configuration_table[i].vendor_table;
-}
-
-  return 

[PATCH] types: Fix typo

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
Just a small grammar mistake.

-- 
Regards
Vladimir 'phcoder' Serbinenko
From e597e474b4ac0423d42902708d536670dba44a1c Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:19:02 +0200
Subject: [PATCH] types: Fix typo

Just a small grammar mistake.

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/grub/types.h b/include/grub/types.h
index 0d96006fe..45536a661 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -349,7 +349,7 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 /*
  * The grub_absolute_pointer() macro borrows the idea from Linux kernel of using
  * RELOC_HIDE() macro to stop GCC from checking the result of pointer arithmetic
- * and also it's conversion to be inside the symbol's boundary [1]. The check
+ * and also its conversion to be inside the symbol's boundary [1]. The check
  * is sometimes false positive, especially it is controversial to emit the array
  * bounds [-Warray-bounds] warning on all hardwired literal pointers since GCC
  * 11/12 [2]. Unless a good solution can be settled, for the time being we
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] lsefi: Add missing static qualifier

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
known_protocols isn't used anywhere else and even misses grub_ prefix, so
let's make it local (static).

-- 
Regards
Vladimir 'phcoder' Serbinenko
From 42b026a69bdb69025499ba761f40d7cb7e0a16d1 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:15:54 +0200
Subject: [PATCH] lsefi: Add missing static qualifier

known_protocols isn't used anywhere else and even misses grub_ prefix, so
let's make it local (static).

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/commands/efi/lsefi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c
index 05e2e511e..95cba5baf 100644
--- a/grub-core/commands/efi/lsefi.c
+++ b/grub-core/commands/efi/lsefi.c
@@ -29,7 +29,7 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-struct known_protocol
+static struct known_protocol
 {
   grub_guid_t guid;
   const char *name;
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] acpi: Mark MADT entries as packed.

2023-10-31 Thread Vladimir 'phcoder' Serbinenko
No alignment is guaranteed and in fact on my ia64 sapic is aligned
to 4 bytes instead of 8 and causes a trap. It affects only rarely used
lsacpi command and so went unnoticed.

-- 
Regards
Vladimir 'phcoder' Serbinenko
From 9d03ab04df3b723058fb0b7c30576e1330cbad5d Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Tue, 31 Oct 2023 18:27:19 +0100
Subject: [PATCH] acpi: Mark MADT entries as packed.

No alignment is guaranteed and in fact on my ia64 sapic is aligned
to 4 bytes instead of 8 and causes a trap. It affects only rarely used
lsacpi command and so went unnoticed.

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/acpi.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/grub/acpi.h b/include/grub/acpi.h
index 17aadb802..87220e337 100644
--- a/include/grub/acpi.h
+++ b/include/grub/acpi.h
@@ -112,7 +112,7 @@ struct grub_acpi_madt_entry_lapic
   grub_uint8_t acpiid;
   grub_uint8_t apicid;
   grub_uint32_t flags;
-};
+} GRUB_PACKED;
 
 struct grub_acpi_madt_entry_ioapic
 {
@@ -121,7 +121,7 @@ struct grub_acpi_madt_entry_ioapic
   grub_uint8_t pad;
   grub_uint32_t address;
   grub_uint32_t global_sys_interrupt;
-};
+} GRUB_PACKED;
 
 struct grub_acpi_madt_entry_interrupt_override
 {
@@ -148,7 +148,7 @@ struct grub_acpi_madt_entry_sapic
   grub_uint8_t pad;
   grub_uint32_t global_sys_interrupt_base;
   grub_uint64_t addr;
-};
+} GRUB_PACKED;
 
 struct grub_acpi_madt_entry_lsapic
 {
@@ -160,7 +160,7 @@ struct grub_acpi_madt_entry_lsapic
   grub_uint32_t flags;
   grub_uint32_t cpu_uid;
   grub_uint8_t cpu_uid_str[0];
-};
+} GRUB_PACKED;
 
 struct grub_acpi_madt_entry_platform_int_source
 {
@@ -172,7 +172,7 @@ struct grub_acpi_madt_entry_platform_int_source
   grub_uint8_t sapic_vector;
   grub_uint32_t global_sys_int;
   grub_uint32_t src_flags;
-};
+} GRUB_PACKED;
 
 enum
   {
-- 
2.39.2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Relocation overflow on RISC-V with multi-range memory layout

2023-10-14 Thread Vladimir 'phcoder' Serbinenko
I looked into it and found out that current code misses both got and
trampolines. I have a template for solution but I didn't test it yet.
Can you upload your EFI images (RISCV_VIRT_CODE.fd and
RISCV_VIRT_VARS.fd) somewhere so I don't have to compile myself?
https://github.com/phcoder/GRUB/tree/riscv

On Thu, Oct 12, 2023 at 2:30 AM Wu, Fei  wrote:
>
> On 10/11/2023 9:50 PM, Vladimir 'phcoder' Serbinenko wrote:
> >
> >
> > Le mer. 11 oct. 2023, 12:20, Wu, Fei  > <mailto:fei2...@intel.com>> a écrit :
> >
> > On 10/9/2023 11:14 AM, Wu, Fei wrote:
> > > On 9/27/2023 11:23 PM, Vladimir 'phcoder' Serbinenko wrote:
> > >> That is not the correct solution. Correct solution is to use
> > trampoline
> > >> facility like e.g. ppc does. Can you post the full reproduction
> > >> instructions?
> > >>
> > Hi Vladimir,
> >
> > Could you please explain a little more about why this is not good, and
> > how does the trampoline address that? IIUC, x86_64 sets
> > GRUB_EFI_MAX_USABLE_ADDRESS to 0x for the same reason.
> >
> > x86_64 reason is different. It's because some EFI implementations don't
> > map RAM above 4GiB contrary to the spec.
> > Trampolines are small piece of code that is inserted by linker to
> > provide absolute jump. Trampolines are always allocated together with
> > the module and so they are reachable by relative jump. Basically what
> > they do then is:
> > ptr=
> > return (*ptr) (...);
> > On most platforms that translates to a load+register jump. Let me see if
> > I can do it quickly. Will you be able to test?
> >
> Thank you Vladimir. Sure, I can test it, let me know when your code is
> ready.
>
> Best Regards,
> Fei.
>
> >
> > Thanks,
> > Fei.
> >
> > > 1. prepare the host for pcie passthrough, e.g. on ubuntu, put
> > something
> > > like the following to kernel cmd, the pci ids are the pci devices to
> > > passthrough:
> > >   intel_iommu=on iommu=pt vfio-pci.ids=10de:0f02,10de:0e08
> > >
> > > 2. apply the patch mentioned below to qemu commit ccb86f079a9e4
> > > 3. run qemu as follows:
> > >
> > > qemu-system-riscv64
> > >  -nographic \
> > >  -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
> > >  -m 3G -smp 2 \
> > >  -blockdev
> > >
> > node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
> > >  -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
> > >  -device vfio-pci,host=01:00.0 -device vfio-pci,host=01:00.1 \
> > >  -device virtio-blk-device,drive=hd0 \
> > >  -drive file=fat:rw:/home/wufei/src/fat,id=hd0
> > >
> > > 4. build and put grub.efi to the directory 'fat'
> > > 5. on uefi shell, run grub.efi
> > >
> > > Thanks,
> > > Fei.
> > >
> > >> Le lun. 25 sept. 2023, 10:53, Wu, Fei  > <mailto:fei2...@intel.com>
> > >> <mailto:fei2...@intel.com <mailto:fei2...@intel.com>>> a écrit :
> > >>
> > >> Hi All,
> > >>
> > >> I'm enabling PCIe passthrough on qemu riscv, the physical memory
> > >> range between 3GB and 4GB is reserved. Therefore if guest has
> > 4GB ram,
> > >> two ranges are created as [2G, 3G) and [4G, 7G). More details
> > can be
> > >> found here:
> > >>
> >  
> > https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/
> >  
> > <https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/>
> >  
> > <https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/
> >  
> > <https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/>>
> > >>
> > >> When run grub.efi from uefi shell, a relocation problem
> > happened in
> > >> grub_arch_dl_relocate_symbols() of grub-core/kern/riscv/dl.c:
> > >>
> > >> case R_RISCV_CALL:
> > >> case R_RISCV_CALL_PLT:
> > >>   {
> > >> grub_uint32_t *abs_place = place;
> > >> grub_ssize_t 

Re: Relocation overflow on RISC-V with multi-range memory layout

2023-10-11 Thread Vladimir 'phcoder' Serbinenko
Le mer. 11 oct. 2023, 12:20, Wu, Fei  a écrit :

> On 10/9/2023 11:14 AM, Wu, Fei wrote:
> > On 9/27/2023 11:23 PM, Vladimir 'phcoder' Serbinenko wrote:
> >> That is not the correct solution. Correct solution is to use trampoline
> >> facility like e.g. ppc does. Can you post the full reproduction
> >> instructions?
> >>
> Hi Vladimir,
>
> Could you please explain a little more about why this is not good, and
> how does the trampoline address that? IIUC, x86_64 sets
> GRUB_EFI_MAX_USABLE_ADDRESS to 0x for the same reason.
>
x86_64 reason is different. It's because some EFI implementations don't map
RAM above 4GiB contrary to the spec.
Trampolines are small piece of code that is inserted by linker to provide
absolute jump. Trampolines are always allocated together with the module
and so they are reachable by relative jump. Basically what they do then is:
ptr=
return (*ptr) (...);
On most platforms that translates to a load+register jump. Let me see if I
can do it quickly. Will you be able to test?

>
> Thanks,
> Fei.
>
> > 1. prepare the host for pcie passthrough, e.g. on ubuntu, put something
> > like the following to kernel cmd, the pci ids are the pci devices to
> > passthrough:
> >   intel_iommu=on iommu=pt vfio-pci.ids=10de:0f02,10de:0e08
> >
> > 2. apply the patch mentioned below to qemu commit ccb86f079a9e4
> > 3. run qemu as follows:
> >
> > qemu-system-riscv64
> >  -nographic \
> >  -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
> >  -m 3G -smp 2 \
> >  -blockdev
> > node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
> >  -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
> >  -device vfio-pci,host=01:00.0 -device vfio-pci,host=01:00.1 \
> >  -device virtio-blk-device,drive=hd0 \
> >  -drive file=fat:rw:/home/wufei/src/fat,id=hd0
> >
> > 4. build and put grub.efi to the directory 'fat'
> > 5. on uefi shell, run grub.efi
> >
> > Thanks,
> > Fei.
> >
> >> Le lun. 25 sept. 2023, 10:53, Wu, Fei  >> <mailto:fei2...@intel.com>> a écrit :
> >>
> >> Hi All,
> >>
> >> I'm enabling PCIe passthrough on qemu riscv, the physical memory
> >> range between 3GB and 4GB is reserved. Therefore if guest has 4GB
> ram,
> >> two ranges are created as [2G, 3G) and [4G, 7G). More details can be
> >> found here:
> >>
> https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/
> <
> https://lore.kernel.org/all/cakmqykmtazt5sacumd4vxyfgaqibpzqjahttsusb+yekhcy...@mail.gmail.com/T/
> >
> >>
> >> When run grub.efi from uefi shell, a relocation problem happened in
> >> grub_arch_dl_relocate_symbols() of grub-core/kern/riscv/dl.c:
> >>
> >> case R_RISCV_CALL:
> >> case R_RISCV_CALL_PLT:
> >>   {
> >> grub_uint32_t *abs_place = place;
> >> grub_ssize_t off = sym_addr - (grub_addr_t) place;
> >> grub_uint32_t hi20, lo12;
> >>
> >> if (off != (grub_int32_t) off)
> >>   return grub_error (GRUB_ERR_BAD_MODULE, "relocation
> >> overflow");
> >>
> >> It requires `off' in the range of int32, but it's not enforced
> since the
> >> >4GB memory can be used. I'm not familiar with grub, but this patch
> does
> >> work for me:
> >>
> >> --- a/include/grub/riscv64/efi/memory.h
> >> +++ b/include/grub/riscv64/efi/memory.h
> >> @@ -1,6 +1,6 @@
> >>  #ifndef GRUB_MEMORY_CPU_HEADER
> >>  #include 
> >>
> >> -#define GRUB_EFI_MAX_USABLE_ADDRESS 0xULL
> >> +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xULL
> >>
> >> Any comments?
> >>
> >> Thanks,
> >> Fei.
> >>
> >> ___
> >> Grub-devel mailing list
> >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> >> https://lists.gnu.org/mailman/listinfo/grub-devel
> >> <https://lists.gnu.org/mailman/listinfo/grub-devel>
> >>
> >>
> >> ___
> >> Grub-devel mailing list
> >> Grub-devel@gnu.org
> >> https://lists.gnu.org/mailman/listinfo/grub-devel
> >
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] relocator: Switch to own page table while moving chunks on x86-64

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From a6ad0d064389b80714128e662e4f447a860bb117 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Tue, 11 Jul 2023 04:58:23 +0200
Subject: [PATCH] relocator: Switch to own page table while moving chunks on
 x86-64

We need to avoid clobering existing table between starting of chunk movers
and the moment we install target page table. Generate temporary table for
this rather than hoping that we don't clober existing one.

Fixes 64-bit GhostBSD on 64-bit EFI

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/lib/i386/relocator_common_c.c | 86 -
 grub-core/lib/mips/relocator.c  |  7 ++
 grub-core/lib/powerpc/relocator.c   |  6 ++
 grub-core/lib/relocator.c   |  5 +-
 include/grub/relocator_private.h|  2 +
 5 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/grub-core/lib/i386/relocator_common_c.c b/grub-core/lib/i386/relocator_common_c.c
index 7be609b73..aa24b8abf 100644
--- a/grub-core/lib/i386/relocator_common_c.c
+++ b/grub-core/lib/i386/relocator_common_c.c
@@ -41,20 +41,104 @@ extern grub_size_t grub_relocator_forward_chunk_size;
 
 #define RELOCATOR_SIZEOF(x)	(_relocator##x##_end - _relocator##x##_start)
 
-grub_size_t grub_relocator_align = 1;
 grub_size_t grub_relocator_forward_size;
 grub_size_t grub_relocator_backward_size;
+grub_size_t grub_relocator_preamble_size = 0;
 #ifdef __x86_64__
+grub_size_t grub_relocator_align = 4096;
 grub_size_t grub_relocator_jumper_size = 12;
 #else
+grub_size_t grub_relocator_align = 1;
 grub_size_t grub_relocator_jumper_size = 7;
 #endif
 
+#ifdef __x86_64__
+static grub_uint64_t max_ram_size;
+
+  /* Helper for grub_get_multiboot_mmap_count.  */
+static int
+max_hook (grub_uint64_t addr,
+	  grub_uint64_t size,
+	  grub_memory_type_t type __attribute__ ((unused)),
+	  void *data __attribute__ ((unused)))
+{
+  if (addr + size > max_ram_size)
+max_ram_size = addr + size;
+  return 0;
+}
+
+static grub_uint64_t
+find_max_size (void)
+{
+  if (!max_ram_size)
+{
+  max_ram_size = 1ULL << 32;
+
+  grub_mmap_iterate (max_hook, NULL);
+}
+
+  return max_ram_size;
+}
+
+void
+grub_cpu_relocator_preamble (void *rels)
+{
+  grub_uint64_t nentries = (find_max_size () + 0x1f) >> 21;
+  grub_uint64_t npt2pages = (nentries + 0x1ff) >> 9;
+  grub_uint64_t npt3pages = (npt2pages + 0x1ff) >> 9;
+  grub_uint8_t *p = rels;
+  grub_uint64_t *pt4 = (grub_uint64_t *) (p + 0x1000);
+  grub_uint64_t *pt3 = pt4 + 0x200;
+  grub_uint64_t *pt2 = pt3 + (npt3pages << 9);
+  grub_uint64_t *endpreamble = pt2 + (npt2pages << 9);
+  grub_uint64_t i;
+
+  *p++ = 0x48;
+  *p++ = 0xb8;
+  *(grub_uint64_t *)p = (grub_uint64_t)pt4;
+  p += 8;
+  *p++ = 0x0f;
+  *p++ = 0x22;
+  *p++ = 0xd8;
+
+  *p++ = 0xe9;
+  *(grub_uint32_t *)p = (grub_uint8_t *)endpreamble - p - 4;
+
+  for (i = 0; i < npt3pages; i++)
+pt4[i] = ((grub_uint64_t)pt3 + (i << 12)) | 7;
+
+  for (i = 0; i < npt2pages; i++)
+pt3[i] = ((grub_uint64_t)pt2 + (i << 12)) | 7;
+
+  for (i = 0; i < (npt2pages << 9); i++)
+pt2[i] = (i << 21) | 0x87;
+}
+
+static void
+compute_preamble_size (void)
+{
+  grub_uint64_t nentries = (find_max_size () + 0x1f) >> 21;
+  grub_uint64_t npt2pages = (nentries + 0x1ff) >> 9;
+  grub_uint64_t npt3pages = (npt2pages + 0x1ff) >> 9;
+  grub_relocator_preamble_size = (npt2pages + npt3pages + 1 + 1) << 12;
+}
+
+#else
+void
+grub_cpu_relocator_preamble (void *rels __attribute__((unused)))
+{
+}
+#endif
+
+
 void
 grub_cpu_relocator_init (void)
 {
   grub_relocator_forward_size = RELOCATOR_SIZEOF (_forward);
   grub_relocator_backward_size = RELOCATOR_SIZEOF (_backward);
+#ifdef __x86_64__
+  compute_preamble_size ();
+#endif
 }
 
 void
diff --git a/grub-core/lib/mips/relocator.c b/grub-core/lib/mips/relocator.c
index 773f3b769..76c3c3bf2 100644
--- a/grub-core/lib/mips/relocator.c
+++ b/grub-core/lib/mips/relocator.c
@@ -45,6 +45,8 @@ grub_size_t grub_relocator_align = sizeof (grub_uint32_t);
 grub_size_t grub_relocator_forward_size;
 grub_size_t grub_relocator_backward_size;
 grub_size_t grub_relocator_jumper_size = JUMP_SIZEOF + REGW_SIZEOF;
+grub_size_t grub_relocator_preamble_size = 0;
+
 
 void
 grub_cpu_relocator_init (void)
@@ -53,6 +55,11 @@ grub_cpu_relocator_init (void)
   grub_relocator_backward_size = RELOCATOR_SIZEOF(backward);
 }
 
+void
+grub_cpu_relocator_preamble (void *rels)
+{
+}
+
 static void
 write_reg (int regn, grub_uint32_t val, void **target)
 {
diff --git a/grub-core/lib/powerpc/relocator.c b/grub-core/lib/powerpc/relocator.c
index 15aeb0246..70dbcb3f1 100644
--- a/grub-core/lib/powerpc/relocator.c
+++ b/grub-core/lib/powerpc/relocator.c
@@ -43,6 +43,7 @@ grub_size_t grub_relocator_align = sizeof (grub_uint32_t);
 grub_size_t grub_relocator_forward_size;
 grub_size_t grub_relocator_backward_size;
 grub_size_t grub_relocator_jumper_size = JUMP_SIZEOF + REGW_SIZEOF;
+grub_size_t grub_relocator_preamble_size = 0;
 
 void
 grub_cpu_relocator_init (void)
@@ -51,6 +52,11 @@ 

[PATCH 2/2] loader/bsd: Improve loading of *BSD on EFI platforms

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 9cb94e2d33f1e4f11a2f9cebdeb6e6a3194b87cf Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 6 Jul 2023 01:42:04 +0200
Subject: [PATCH 2/2] loader/bsd: Improve loading of *BSD on EFI platforms

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/loader/i386/bsd.c | 515 +++-
 include/grub/i386/freebsd_linker.h  |  39 +++
 include/grub/i386/netbsd_bootinfo.h |  12 +-
 include/grub/i386/openbsd_bootarg.h |  24 ++
 4 files changed, 495 insertions(+), 95 deletions(-)

diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
index 1f9128f6f..58b976861 100644
--- a/grub-core/loader/i386/bsd.c
+++ b/grub-core/loader/i386/bsd.c
@@ -40,6 +40,8 @@
 #ifdef GRUB_MACHINE_PCBIOS
 #include 
 #endif
+#include 
+#include 
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -48,10 +50,11 @@ GRUB_MOD_LICENSE ("GPLv3+");
 #include 
 #endif
 #ifdef GRUB_MACHINE_EFI
+#include 
 #include 
-#define NETBSD_DEFAULT_VIDEO_MODE "800x600"
+#define BSD_DEFAULT_VIDEO_MODE "800x600"
 #else
-#define NETBSD_DEFAULT_VIDEO_MODE "text"
+#define BSD_DEFAULT_VIDEO_MODE "text"
 #include 
 #endif
 #include 
@@ -76,6 +79,11 @@ static int is_elf_kernel, is_64bit;
 static grub_uint32_t openbsd_root;
 static struct grub_relocator *relocator = NULL;
 static struct grub_openbsd_ramdisk_descriptor openbsd_ramdisk;
+#ifdef GRUB_MACHINE_EFI
+static struct grub_openbsd_bootarg_efiinfo openbsd_efi_info;
+#endif
+
+static grub_err_t grub_bsd_setup_video (void);
 
 struct bsd_tag
 {
@@ -219,7 +227,7 @@ grub_bsd_get_device (grub_uint32_t * biosdev,
 }
 
 static grub_err_t
-grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len)
+grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len, int is_kernel_tag)
 {
   struct bsd_tag *newtag;
 
@@ -231,8 +239,7 @@ grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len)
   newtag->next = NULL;
   *ptr = newtag->data;
 
-  if (kernel_type == KERNEL_TYPE_FREEBSD
-  && type == (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_SMAP))
+  if (kernel_type == KERNEL_TYPE_FREEBSD && is_kernel_tag)
 {
   struct bsd_tag *p;
   for (p = tags;
@@ -259,20 +266,34 @@ grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len)
   return GRUB_ERR_NONE;
 }
 
-grub_err_t
-grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len)
+static grub_err_t
+grub_bsd_add_meta_real (grub_uint32_t type, const void *data, grub_uint32_t len, int is_kernel_tag)
 {
   grub_err_t err;
   void *ptr = NULL;
 
-  err = grub_bsd_add_meta_ptr (type, , len);
+  err = grub_bsd_add_meta_ptr (type, , len, is_kernel_tag);
   if (err)
 return err;
-  if (len)
+  if (data && len)
 grub_memcpy (ptr, data, len);
+  else if (!data && len)
+grub_memset (ptr, 0, len);
+
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+grub_bsd_add_kernel_meta (grub_uint32_t type, const void *data, grub_uint32_t len)
+{
+  return grub_bsd_add_meta_real (type, data, len, 1);
+}
+
+grub_err_t
+grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len)
+{
+  return grub_bsd_add_meta_real (type, data, len, 0);
+}
 
 struct grub_e820_mmap
 {
@@ -404,8 +425,8 @@ grub_bsd_add_mmap (void)
   else if (kernel_type == KERNEL_TYPE_OPENBSD)
 grub_bsd_add_meta (OPENBSD_BOOTARG_MMAP, buf0, len);
   else
-grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
-		   FREEBSD_MODINFOMD_SMAP, buf0, len);
+grub_bsd_add_kernel_meta (FREEBSD_MODINFO_METADATA |
+			  FREEBSD_MODINFOMD_SMAP, buf0, len);
 
   grub_free (buf0);
 
@@ -462,7 +483,7 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
 	  void *cmdline;
 	  char *p;
 
-	  if (grub_bsd_add_meta_ptr (FREEBSD_MODINFO_ARGS, , n))
+	  if (grub_bsd_add_meta_ptr (FREEBSD_MODINFO_ARGS, , n, 0))
 	return grub_errno;
 
 	  p = cmdline;
@@ -592,6 +613,80 @@ freebsd_get_zfs (void)
   grub_free (uuid);
 }
 
+#ifdef GRUB_MACHINE_EFI
+
+#define NEXT_MEMORY_DESCRIPTOR(desc, size)	\
+  ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
+
+static void
+grub_swap_buffers(void *a, void *b, grub_size_t n)
+{
+  grub_uint8_t *ap = a, *bp = b;
+  for (; n; n--, ap++, bp++)
+{
+  grub_uint8_t t = *ap;
+  *ap = *bp;
+  *bp = t;
+}
+}
+
+static void
+grub_efi_sort_memory_map(void *buf, grub_efi_uintn_t desc_size, grub_efi_uintn_t mmap_size)
+{
+  int done_any = 1;
+
+  while (done_any)
+{
+  grub_efi_memory_descriptor_t *d_cur = buf;
+  grub_efi_memory_descriptor_t *d_next = NEXT_MEMORY_DESCRIPTOR(d_cur, desc_size);
+
+  done_any = 0;
+  for (; d_next < NEXT_MEMORY_DESCRIPTOR(buf, mmap_size);
+	   d_cur = d_next, d_next = NEXT_MEMORY_DESCRIPTOR(d_cur, desc_size))
+	{
+	  if (d_next->physical_start < d_cur->physical_start)
+	{
+	  done_any = 1;
+	  grub_swap_buffers(d_cur, d_next, desc_size);
+	}
+	}
+}
+}
+
+static int
+iterate_get_zerotables_size (grub_linuxbios_table_item_t table_item, void *data)
+{
+ 

[PATCH 1/2] smbios: Export grub_smbios_get_eps3 function

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 4f8bdb060a2915587ac15093f492f0d9784e56f4 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sat, 8 Jul 2023 08:28:51 +0200
Subject: [PATCH 1/2] smbios: Export grub_smbios_get_eps3 function

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/commands/smbios.c | 2 +-
 include/grub/smbios.h   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/grub-core/commands/smbios.c b/grub-core/commands/smbios.c
index 1a9086ddd..8d9b2e548 100644
--- a/grub-core/commands/smbios.c
+++ b/grub-core/commands/smbios.c
@@ -51,7 +51,7 @@ grub_smbios_get_eps (void)
 }
 
 /* Locate the SMBIOS3 entry point structure depending on the hardware. */
-static struct grub_smbios_eps3 *
+struct grub_smbios_eps3 *
 grub_smbios_get_eps3 (void)
 {
   static struct grub_smbios_eps3 *eps = NULL;
diff --git a/include/grub/smbios.h b/include/grub/smbios.h
index 15ec260b3..0dfa7c348 100644
--- a/include/grub/smbios.h
+++ b/include/grub/smbios.h
@@ -65,5 +65,6 @@ extern struct grub_smbios_eps *grub_machine_smbios_get_eps (void);
 extern struct grub_smbios_eps3 *grub_machine_smbios_get_eps3 (void);
 
 extern struct grub_smbios_eps *EXPORT_FUNC (grub_smbios_get_eps) (void);
+extern struct grub_smbios_eps3 *grub_smbios_get_eps3 (void);
 
 #endif /* ! GRUB_SMBIOS_HEADER */
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 0/2] Fix *BSD loading on EFI

2023-10-08 Thread Vladimir 'phcoder' Serbinenko
Due to several bugs in BSD loader recent *BSD doesn't load on EFI. These 2
patches fix it. Tested on GhostBSD, DragonFlyBSD, NetBSD and OpenBSD
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 01/01] loader/bsd: Add missing zeros

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 1be6ed3500b24ef7327ab2ea99c23488102a977b Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Mon, 10 Jul 2023 13:05:21 +0200
Subject: [PATCH 01/01] loader/bsd: Add missing zeros

kern_end is 64-bit and so we need to add this additional zero.
entry is unused and is explicitly zero in own FreeBSD bootloader

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/loader/i386/bsd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
index 58b976861..ce9d8f4e3 100644
--- a/grub-core/loader/i386/bsd.c
+++ b/grub-core/loader/i386/bsd.c
@@ -896,7 +896,7 @@ grub_freebsd_boot (void)
 
   err = grub_relocator_alloc_chunk_align (relocator, ,
 	  0x1, 0x9,
-	  (is_64bit ? 3 : 9) * sizeof (grub_uint32_t)
+	  (is_64bit ? 4 : 9) * sizeof (grub_uint32_t)
 	  + sizeof (bi), 4,
 	  GRUB_RELOCATOR_PREFERENCE_NONE,
 	  0);
@@ -956,9 +956,10 @@ grub_freebsd_boot (void)
   state.rsp = stack_target;
   state.rip = (((grub_uint64_t) entry_hi) << 32) | entry;
 
-  stack[0] = entry;
+  stack[0] = 0;
   stack[1] = bi.tags;
   stack[2] = kern_end;
+  stack[3] = 0;
   return grub_relocator64_boot (relocator, state, 0, 0x4000);
 }
   else
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 01/01] loader/bsd: Fix loading after unaligned module

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From fe519348967c7096e4b9466fc39bd393cd58319a Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Mon, 10 Jul 2023 17:17:35 +0200
Subject: [PATCH 01/01] loader/bsd: Fix loading after unaligned module

Current code implicitly assumes that aligning chunk_size + *kern_end is
the same as aligning on curload which is not the case because
chunk_size starts at zero even if *kern_end is unaligned and ALIGN_PAGE
moved curload to an aligned position but not *kern_end + chunk_size

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/loader/i386/bsdXX.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c
index 09d909f1b..d3de8a29b 100644
--- a/grub-core/loader/i386/bsdXX.c
+++ b/grub-core/loader/i386/bsdXX.c
@@ -88,10 +88,9 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
   Elf_Shnum shnum;
   grub_addr_t curload, module;
   grub_err_t err;
-  grub_size_t chunk_size = 0;
   void *chunk_src;
 
-  curload = module = ALIGN_PAGE (*kern_end);
+  module = ALIGN_PAGE (*kern_end);
 
   err = read_headers (file, argv[0], , );
   if (err != GRUB_ERR_NONE)
@@ -101,6 +100,8 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
   if (err != GRUB_ERR_NONE)
 goto out;
 
+  curload = module;
+
   for (s = shdr; s < (Elf_Shdr *) ((grub_uint8_t *) shdr + shnum * e.e_shentsize);
s = (Elf_Shdr *) ((grub_uint8_t *) s + e.e_shentsize))
 {
@@ -108,21 +109,24 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
 	continue;
 
   if (s->sh_addralign)
-	chunk_size = ALIGN_UP (chunk_size + *kern_end, s->sh_addralign)
-	  - *kern_end;
+	curload = ALIGN_UP (curload, s->sh_addralign);
 
-  chunk_size += s->sh_size;
+  curload += s->sh_size;
 }
 
+  *kern_end = ALIGN_PAGE (curload);
+
   {
 grub_relocator_chunk_t ch;
 err = grub_relocator_alloc_chunk_addr (relocator, ,
-	   module, chunk_size);
+	   module, curload - module);
 if (err != GRUB_ERR_NONE)
   goto out;
 chunk_src = get_virtual_current_address (ch);
   }
 
+  curload = module;
+
   for (s = shdr; s < (Elf_Shdr *) ((grub_uint8_t *) shdr + shnum * e.e_shentsize);
s = (Elf_Shdr *) ((grub_uint8_t *) s + e.e_shentsize))
 {
@@ -141,13 +145,13 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator,
 	{
 	default:
 	case SHT_PROGBITS:
-	  err = load (file, argv[0], (grub_uint8_t *) chunk_src + curload - *kern_end,
+	  err = load (file, argv[0], (grub_uint8_t *) chunk_src + curload - module,
 		  s->sh_offset, s->sh_size);
 	  if (err != GRUB_ERR_NONE)
 	goto out;
 	  break;
 	case SHT_NOBITS:
-	  grub_memset ((grub_uint8_t *) chunk_src + curload - *kern_end, 0,
+	  grub_memset ((grub_uint8_t *) chunk_src + curload - module, 0,
 		   s->sh_size);
 	  break;
 	}
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 1/1] types: Fix typo

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 8d083bc12f7129616c9cf73c8a1e97d05810322d Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Sun, 13 Aug 2023 09:19:02 +0200
Subject: [PATCH 1/1] types: Fix typo

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/grub/types.h b/include/grub/types.h
index ce7fa898f..4deb3bb64 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -349,7 +349,7 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 /*
  * The grub_absolute_pointer() macro borrows the idea from Linux kernel of using
  * RELOC_HIDE() macro to stop GCC from checking the result of pointer arithmetic
- * and also it's conversion to be inside the symbol's boundary [1]. The check
+ * and also its conversion to be inside the symbol's boundary [1]. The check
  * is sometimes false positive, especially it is controversial to emit the array
  * bounds [-Warray-bounds] warning on all hardwired literal pointers since GCC
  * 11/12 [2]. Unless a good solution can be settled, for the time being we
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 4/4] 10_illumos: Use --noescape so that $ZFS_BOOTFS is passed

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 2ee3100e1d3febaebfb244393d676fe43c78e802 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Wed, 19 Jul 2023 15:27:26 +0200
Subject: [PATCH 4/4] 10_illumos: Use --noescape so that $ZFS_BOOTFS is passed
 properly

Signed-off-by: Vladimir Serbinenko 
---
 util/grub.d/10_illumos.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/grub.d/10_illumos.in b/util/grub.d/10_illumos.in
index a133e1b3f..5649e441f 100644
--- a/util/grub.d/10_illumos.in
+++ b/util/grub.d/10_illumos.in
@@ -47,7 +47,7 @@ message="$(gettext_printf "Loading kernel of Illumos ...")"
 	fi
 	zfs-bootfs $($grub_mkrelpath /) ZFS_BOOTFS
 echo '$(echo "$message" | grub_quote)'
-	multiboot $($grub_mkrelpath /platform/i86pc/kernel)/\$ISADIR/unix /platform/i86pc/kernel/\$ISADIR/unix -B \$ZFS_BOOTFS,console=text
+	multiboot --noescape $($grub_mkrelpath /platform/i86pc/kernel)/\$ISADIR/unix /platform/i86pc/kernel/\$ISADIR/unix -B \$ZFS_BOOTFS,console=text
 	module $($grub_mkrelpath /platform/i86pc)/\$ISADIR/boot_archive /platform/i86pc/\$ISADIR/boot_archive
 }
 EOF
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 3/4] loader/xen: Add --noescape option.

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From cb89ee17a09c34eb604e3b2543b104fac25d2fa8 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Wed, 19 Jul 2023 15:26:41 +0200
Subject: [PATCH 3/4] loader/xen: Add --noescape option.

---
 grub-core/loader/i386/xen.c | 43 +++--
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c
index d24ef151b..12d920294 100644
--- a/grub-core/loader/i386/xen.c
+++ b/grub-core/loader/i386/xen.c
@@ -638,6 +638,14 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
   grub_addr_t kern_start;
   grub_addr_t kern_end;
   grub_size_t sz;
+  int no_escape = 0;
+
+  if (argc != 0 && grub_strcmp (argv[0], "--noescape") == 0)
+{
+  argc--;
+  argv++;
+  no_escape = 1;
+}
 
   if (argc == 0)
 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
@@ -650,7 +658,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
   err = grub_create_loader_cmdline (argc - 1, argv + 1,
 (char *) xen_state.next_start.cmd_line,
 sizeof (xen_state.next_start.cmd_line) - 1,
-GRUB_VERIFY_KERNEL_CMDLINE, 0);
+GRUB_VERIFY_KERNEL_CMDLINE, no_escape);
   if (err)
 return err;
 
@@ -845,17 +853,30 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
   grub_relocator_chunk_t ch;
   grub_size_t cmdline_len;
   int nounzip = 0;
+  int option_found = 0;
+  int no_escape = 0;
   grub_file_t file;
 
-  if (argc == 0)
-return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
-
-  if (grub_strcmp (argv[0], "--nounzip") == 0)
+  do
 {
-  argv++;
-  argc--;
-  nounzip = 1;
-}
+  option_found = 0;
+
+  if (argc != 0 && grub_strcmp (argv[0], "--nounzip") == 0)
+	{
+	  argc--;
+	  argv++;
+	  option_found = 1;
+	  nounzip = 1;
+	}
+
+  if (argc != 0 && grub_strcmp (argv[0], "--noescape") == 0)
+	{
+	  argc--;
+	  argv++;
+	  option_found = 1;
+	  no_escape = 1;
+	}
+} while (option_found);
 
   if (argc == 0)
 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
@@ -910,7 +931,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
 return grub_errno;
   size = grub_file_size (file);
 
-  cmdline_len = grub_loader_cmdline_size (argc - 1, argv + 1, 0);
+  cmdline_len = grub_loader_cmdline_size (argc - 1, argv + 1, no_escape);
 
   err = grub_relocator_alloc_chunk_addr (xen_state.relocator, ,
 	 xen_state.max_addr, cmdline_len);
@@ -919,7 +940,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
 
   err = grub_create_loader_cmdline (argc - 1, argv + 1,
 get_virtual_current_address (ch), cmdline_len,
-GRUB_VERIFY_MODULE_CMDLINE, 0);
+GRUB_VERIFY_MODULE_CMDLINE, no_escape);
   if (err)
 goto fail;
 
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/4] loader/multiboot: Add --noescape option

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From bc47b53012d526d85a4ca7f493322094695b193e Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Wed, 19 Jul 2023 15:25:14 +0200
Subject: [PATCH 2/4] loader/multiboot: Add --noescape option

This is needed to boot Solaris/Illumos on some boot paths that need quotes.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/loader/i386/multiboot_mbi.c | 13 
 grub-core/loader/multiboot.c  | 46 ---
 grub-core/loader/multiboot_mbi2.c | 12 +++
 include/grub/multiboot.h  |  4 +--
 include/grub/multiboot2.h |  4 +--
 5 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
index 9a98e9bfe..c7c9daf18 100644
--- a/grub-core/loader/i386/multiboot_mbi.c
+++ b/grub-core/loader/i386/multiboot_mbi.c
@@ -659,13 +659,13 @@ grub_multiboot_free_mbi (void)
 }
 
 grub_err_t
-grub_multiboot_init_mbi (int argc, char *argv[])
+grub_multiboot_init_mbi (int argc, char *argv[], int no_escape)
 {
   grub_ssize_t len = 0;
 
   grub_multiboot_free_mbi ();
 
-  len = grub_loader_cmdline_size (argc, argv, 0);
+  len = grub_loader_cmdline_size (argc, argv, no_escape);
 
   cmdline = grub_malloc (len);
   if (! cmdline)
@@ -673,12 +673,12 @@ grub_multiboot_init_mbi (int argc, char *argv[])
   cmdline_size = len;
 
   return grub_create_loader_cmdline (argc, argv, cmdline,
- cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE, 0);
+ cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE, no_escape);
 }
 
 grub_err_t
 grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
-			   int argc, char *argv[])
+			   int argc, char *argv[], int no_escape)
 {
   struct module *newmod;
   grub_size_t len = 0;
@@ -691,7 +691,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
   newmod->size = size;
   newmod->next = 0;
 
-  len = grub_loader_cmdline_size (argc, argv, 0);
+  len = grub_loader_cmdline_size (argc, argv, no_escape);
 
   newmod->cmdline = grub_malloc (len);
   if (! newmod->cmdline)
@@ -703,7 +703,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
   total_modcmd += ALIGN_UP (len, 4);
 
   err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
-newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE, 0);
+newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE, no_escape);
+
   if (err)
 {
   grub_free (newmod);
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
index 94be512c4..851f75334 100644
--- a/grub-core/loader/multiboot.c
+++ b/grub-core/loader/multiboot.c
@@ -295,11 +295,14 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
 
 #ifndef GRUB_USE_MULTIBOOT2
   grub_multiboot_quirks = GRUB_MULTIBOOT_QUIRKS_NONE;
+#endif
   int option_found = 0;
+  int no_escape = 0;
 
   do
 {
   option_found = 0;
+#ifndef GRUB_USE_MULTIBOOT2
   if (argc != 0 && grub_strcmp (argv[0], "--quirk-bad-kludge") == 0)
 	{
 	  argc--;
@@ -315,9 +318,17 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
 	  option_found = 1;
 	  grub_multiboot_quirks |= GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL;
 	}
-} while (option_found);
 #endif
 
+  if (argc != 0 && grub_strcmp (argv[0], "--noescape") == 0)
+	{
+	  argc--;
+	  argv++;
+	  option_found = 1;
+	  no_escape = 1;
+	}
+} while (option_found);
+
   if (argc == 0)
 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
@@ -328,7 +339,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
   grub_dl_ref (my_mod);
 
   /* Skip filename.  */
-  GRUB_MULTIBOOT (init_mbi) (argc - 1, argv + 1);
+  GRUB_MULTIBOOT (init_mbi) (argc - 1, argv + 1, no_escape);
 
   grub_relocator_unload (GRUB_MULTIBOOT (relocator));
   GRUB_MULTIBOOT (relocator) = grub_relocator_new ();
@@ -367,18 +378,29 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
   void *module = NULL;
   grub_addr_t target;
   grub_err_t err;
-  int nounzip = 0;
+  int nounzip = 0, noescape = 0, option_found = 0;
   grub_uint64_t lowest_addr = 0;
 
-  if (argc == 0)
-return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
-
-  if (grub_strcmp (argv[0], "--nounzip") == 0)
+  do
 {
-  argv++;
-  argc--;
-  nounzip = 1;
-}
+  option_found = 0;
+
+  if (argc != 0 && grub_strcmp (argv[0], "--nounzip") == 0)
+	{
+	  argc--;
+	  argv++;
+	  option_found = 1;
+	  nounzip = 1;
+	}
+
+  if (argc != 0 && grub_strcmp (argv[0], "--noescape") == 0)
+	{
+	  argc--;
+	  argv++;
+	  option_found = 1;
+	  noescape = 1;
+	}
+} while (option_found);
 
   if (argc == 0)
 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
@@ -420,7 +442,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
   target = 0;
 }
 
-  err = GRUB_MULTIBOOT (add_module) (target, size, argc - 1, argv + 1);
+  err = GRUB_MULTIBOOT (add_module) (target, size, argc - 1, argv + 1, 

[PATCH 1/4] Add "noescape" argument to cmdline creation

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From cadef71f275af55740e33a6f6f7f86b5bd004855 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Wed, 19 Jul 2023 15:09:47 +0200
Subject: [PATCH 1/4] Add "noescape" argument to cmdline creation

If OS parses in a way different from sh-like that GRUB does, escaping does
more harm than good. Note that allows to specify entire command line in a
single argument e.g. multiboot --noescape /kernel "a b c".

This is needed to boot Solaris/Illumos on some boot paths that need quotes.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/lib/cmdline.c   | 40 ++-
 grub-core/loader/arm/linux.c  |  4 +--
 grub-core/loader/arm64/xen_boot.c |  4 +--
 grub-core/loader/efi/linux.c  |  4 +--
 grub-core/loader/i386/linux.c |  2 +-
 grub-core/loader/i386/multiboot_mbi.c |  8 ++---
 grub-core/loader/i386/pc/linux.c  |  2 +-
 grub-core/loader/i386/xen.c   |  6 ++--
 grub-core/loader/mips/linux.c |  4 +--
 grub-core/loader/multiboot_mbi2.c |  8 ++---
 grub-core/loader/powerpc/ieee1275/linux.c |  4 +--
 grub-core/loader/sparc64/ieee1275/linux.c |  4 +--
 include/grub/lib/cmdline.h|  5 +--
 13 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
index ed0b149dc..715392fac 100644
--- a/grub-core/lib/cmdline.c
+++ b/grub-core/lib/cmdline.c
@@ -45,14 +45,14 @@ static unsigned int check_arg (char *c, int *has_space)
   return size;
 }
 
-unsigned int grub_loader_cmdline_size (int argc, char *argv[])
+unsigned int grub_loader_cmdline_size (int argc, char *argv[], int noescape)
 {
   int i;
   unsigned int size = 0;
 
   for (i = 0; i < argc; i++)
 {
-  size += check_arg (argv[i], 0);
+  size += noescape ? grub_strlen(argv[i]) : check_arg (argv[i], 0);
   size++; /* Separator space or NULL.  */
 }
 
@@ -64,16 +64,17 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[])
 
 grub_err_t
 grub_create_loader_cmdline (int argc, char *argv[], char *buf,
-			grub_size_t size, enum grub_verify_string_type type)
+			grub_size_t size, enum grub_verify_string_type type,
+			int noescape)
 {
-  int i, space;
+  int i, space = 0;
   unsigned int arg_size;
   char *c, *orig_buf = buf;
 
   for (i = 0; i < argc; i++)
 {
   c = argv[i];
-  arg_size = check_arg(argv[i], );
+  arg_size = noescape ? grub_strlen(argv[i]) : check_arg(argv[i], );
   arg_size++; /* Separator space or NULL.  */
 
   if (size < arg_size)
@@ -81,21 +82,28 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
 
   size -= arg_size;
 
-  if (space)
-	*buf++ = '"';
-
-  while (*c)
+  if (noescape)
 	{
-	  if (*c == '\\' || *c == '\'' || *c == '"')
-	*buf++ = '\\';
-
-	  *buf++ = *c;
-	  c++;
+	  grub_memcpy(buf, c, arg_size);
+	  buf += arg_size - 1;
 	}
+  else
+	{
+	  if (space)
+	*buf++ = '"';
 
-  if (space)
-	*buf++ = '"';
+	  while (*c)
+	{
+	  if (*c == '\\' || *c == '\'' || *c == '"')
+		*buf++ = '\\';
 
+	  *buf++ = *c;
+	  c++;
+	}
+
+	  if (space)
+	*buf++ = '"';
+	}
   *buf++ = ' ';
 }
 
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
index 19ddedbc2..6a052a0da 100644
--- a/grub-core/loader/arm/linux.c
+++ b/grub-core/loader/arm/linux.c
@@ -375,7 +375,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   grub_loader_set (linux_boot, linux_unload, 0);
 
-  size = grub_loader_cmdline_size (argc, argv);
+  size = grub_loader_cmdline_size (argc, argv, 0);
   linux_args = grub_malloc (size + sizeof (LINUX_IMAGE));
   if (!linux_args)
 {
@@ -387,7 +387,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
   err = grub_create_loader_cmdline (argc, argv,
 linux_args + sizeof (LINUX_IMAGE) - 1, size,
-GRUB_VERIFY_KERNEL_CMDLINE);
+GRUB_VERIFY_KERNEL_CMDLINE, 0);
   if (err)
 goto fail;
 
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
index 26e1472c9..7b55742f5 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -345,7 +345,7 @@ xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
 
   if (argc > 1)
 {
-  binary->cmdline_size = grub_loader_cmdline_size (argc - 1, argv + 1);
+  binary->cmdline_size = grub_loader_cmdline_size (argc - 1, argv + 1, 0);
   binary->cmdline = grub_zalloc (binary->cmdline_size);
   if (!binary->cmdline)
 	{
@@ -355,7 +355,7 @@ xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
 	}
   grub_create_loader_cmdline (argc - 1, argv + 1, binary->cmdline,
   binary->cmdline_size,
-  GRUB_VERIFY_KERNEL_CMDLINE);
+  GRUB_VERIFY_KERNEL_CMDLINE, 0);
   grub_dprintf ("xen_loader",
 		"Xen_boot cmdline @ %p %s, size: 

[PATCH 0/4] Fix escaping of zfs bootinfo for solaris

2023-10-08 Thread Vladimir 'phcoder' Serbinenko
Currently Solaris/Illumos are unbootable if device path contains some
characters including comma used in PCI names
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 13/13] mm: Use %x and a case for displaying sizeof.

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 16e889308c335aaa4c54ba0724b655cffa2ed850 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 13:37:43 +0200
Subject: [PATCH 13/13] mm: Use %x and a case for displaying sizeof.

There is some variance in how compiler treat sizeof especially on
32-bit platforms where it can be naturally either int or long.
Explicit cast solves the issue
---
 grub-core/kern/mm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c
index 792ab0a83..2ba0c184e 100644
--- a/grub-core/kern/mm.c
+++ b/grub-core/kern/mm.c
@@ -238,8 +238,8 @@ grub_mm_init_region (void *addr, grub_size_t size)
*   ||-q->post_size-|size-|
*/
   grub_dprintf ("regions", "Can we extend into region below?"
-" %p + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
-(grub_uint8_t *) q, sizeof(*q), q->size, q->post_size, (grub_uint8_t *) addr);
+" %p + %x + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
+(grub_uint8_t *) q, (int) sizeof(*q), q->size, q->post_size, (grub_uint8_t *) addr);
   if ((grub_uint8_t *) q + sizeof (*q) + q->size + q->post_size ==
 	  (grub_uint8_t *) addr)
 	{
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 12/13] configure: Add RPATH for freetype on NetBSD

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 010efc49a96c972988b4ba8a59d175b9c94fdc3d Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 01:54:09 +0200
Subject: [PATCH 12/13] configure: Add RPATH for freetype on NetBSD

Without this mkfont fails dynamic linking. THis is not ideal
but improves the situation until a better solution is available
---
 configure.ac | 8 
 1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index 9fa0931b3..6f3a08f34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1716,6 +1716,9 @@ if test x"$grub_mkfont_excuse" = x ; then
 CPPFLAGS="$SAVED_CPPFLAGS"
 LIBS="$SAVED_LIBS"
   ], [grub_mkfont_excuse=["need freetype2 library"]])
+  if test x"$grub_mkfont_excuse" = x && test x"$host_kernel" = xnetbsd ; then
+  FREETYPE_LIBS="$FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;
+  fi
 fi
 
 if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
@@ -1770,6 +1773,11 @@ if test x"$grub_build_mkfont_excuse" = x ; then
 LIBS="$SAVED_LIBS"
 CPPFLAGS="$SAVED_CPPFLAGS_2"
   ], [grub_build_mkfont_excuse=["need freetype2 library"]])
+  if test x"$grub_build_mkfont_excuse" = x ; then
+case x"$build_os" in
+  xnetbsd*) BUILD_FREETYPE_LIBS="$BUILD_FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;;
+esac
+  fi
   PKG_CONFIG="$SAVED_PKG_CONFIG"
 fi
 
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 11/13] Support prefixed nvlist symbol names as found on NetBSD

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 186cb47e71ae9d14699c54f93b61ce5d749e8fa8 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 00:01:25 +0200
Subject: [PATCH 11/13] Support prefixed nvlist symbol names as found on NetBSD

---
 configure.ac   | 15 +--
 grub-core/osdep/unix/getroot.c |  8 
 include/grub/util/libnvpair.h  | 12 +---
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2902f9533..9fa0931b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1983,8 +1983,19 @@ fi
 
 if test x"$libzfs_excuse" = x ; then
   AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
-   [],
-   [libzfs_excuse="need nvpair library"])
+   [have_normal_nvpair=yes],
+   [have_normal_nvpair=no])
+  if test x"$have_normal_nvpair" = xno ; then
+AC_CHECK_LIB([nvpair], [opensolaris_nvlist_lookup_string],
+ [have_prefixed_nvpair=yes],
+ [have_prefixed_nvpair=no])
+if test x"$have_prefixed_nvpair" = xyes ; then
+  AC_DEFINE([GRUB_UTIL_NVPAIR_IS_PREFIXED], [1],
+[Define to 1 if libnvpair symbols are prefixed with opensolaris_.])
+else
+  libzfs_excuse="need nvpair library"
+fi
+  fi
 fi
 
 if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index 71cdf2e86..ee11b02fb 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -174,20 +174,20 @@ grub_util_find_root_devices_from_poolname (char *poolname)
   zpool = zpool_open (libzfs, poolname);
   config = zpool_get_config (zpool, NULL);
 
-  if (nvlist_lookup_nvlist (config, "vdev_tree", _tree) != 0)
+  if (NVLIST(lookup_nvlist) (config, "vdev_tree", _tree) != 0)
 error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
 
-  if (nvlist_lookup_nvlist_array (vdev_tree, "children", , _count) != 0)
+  if (NVLIST(lookup_nvlist_array) (vdev_tree, "children", , _count) != 0)
 error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
   assert (nvlist_count > 0);
 
-  while (nvlist_lookup_nvlist_array (children[0], "children",
+  while (NVLIST(lookup_nvlist_array) (children[0], "children",
  , _count) == 0)
 assert (nvlist_count > 0);
 
   for (i = 0; i < nvlist_count; i++)
 {
-  if (nvlist_lookup_string (children[i], "path", ) != 0)
+  if (NVLIST(lookup_string) (children[i], "path", ) != 0)
 	error (1, errno, "nvlist_lookup_string (\"path\")");
 
   struct stat st;
diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h
index 573c7ea81..a3acffb88 100644
--- a/include/grub/util/libnvpair.h
+++ b/include/grub/util/libnvpair.h
@@ -29,9 +29,15 @@
 
 typedef void nvlist_t;
 
-int nvlist_lookup_string (nvlist_t *, const char *, char **);
-int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **);
-int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
+#ifdef GRUB_UTIL_NVPAIR_IS_PREFIXED
+#define NVLIST(x) opensolaris_nvlist_ ## x
+#else
+#define NVLIST(x) nvlist_ ## x
+#endif
+
+int NVLIST(lookup_string) (nvlist_t *, const char *, char **);
+int NVLIST(lookup_nvlist) (nvlist_t *, const char *, nvlist_t **);
+int NVLIST(lookup_nvlist_array) (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
 
 #endif /* ! HAVE_LIBNVPAIR_H */
 
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 10/13] configure: Add *BSD font paths

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From bf73ce71ac89abba3fca52ae3c019da4bebadab0 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Fri, 25 Aug 2023 00:00:52 +0200
Subject: [PATCH 10/13] configure: Add *BSD font paths

---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2fe07fdcb..2902f9533 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1813,7 +1813,7 @@ fi
 
 if test x"$starfield_excuse" = x; then
for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
- for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype; do
+ for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF /usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF; do
 if test -f "$dir/DejaVuSans.$ext"; then
   DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
   break 2
@@ -1835,7 +1835,7 @@ AC_SUBST([DJVU_FONT_SOURCE])
 FONT_SOURCE=
 
 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
-  for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc; do
+  for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc /usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont /usr/local/share/fonts/unifont; do
 if test -f "$dir/unifont.$ext"; then
   md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
   # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 09/13] autogen: Accept python3.10 as a python alternative

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 8ac88c7b071635c7fb68f37f46005e92f794f2c9 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 23:25:48 +0200
Subject: [PATCH 09/13] autogen: Accept python3.10 as a python alternative

NetBSD doesn't provide python or python3
---
 autogen.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/autogen.sh b/autogen.sh
index 5a5c356fd..195daa541 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,7 +9,7 @@ fi
 
 # Detect python
 if [ -z "$PYTHON" ]; then
-  for i in python3 python; do
+  for i in python3 python3.10 python; do
 if command -v "$i" > /dev/null 2>&1; then
   PYTHON="$i"
   echo "Using $PYTHON..."
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 08/13] Rename HAVE_LIBZFS to USE_LIBZFS

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From 378fbafb656bbd6d91d3f07ca6cf0b477ea8b72d Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 23:24:30 +0200
Subject: [PATCH 08/13] Rename HAVE_LIBZFS to USE_LIBZFS

HAVE_LIBZFS is defined by libzfs test and hence conflicts with manual definition.
Split them
---
 configure.ac   | 6 ++
 grub-core/osdep/unix/getroot.c | 4 ++--
 util/getroot.c | 6 +++---
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index da9c8d560..2fe07fdcb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1994,11 +1994,9 @@ fi
 if test x"$libzfs_excuse" = x ; then
   # We need both libzfs and libnvpair for a successful build.
   LIBZFS="-lzfs"
-  AC_DEFINE([HAVE_LIBZFS], [1],
-[Define to 1 if you have the ZFS library.])
   LIBNVPAIR="-lnvpair"
-  AC_DEFINE([HAVE_LIBNVPAIR], [1],
-[Define to 1 if you have the NVPAIR library.])
+  AC_DEFINE([USE_LIBZFS], [1],
+[Define to 1 if ZFS library should be used.])
 fi
 
 AC_SUBST([LIBZFS])
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index cde821eb9..71cdf2e86 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -53,7 +53,7 @@
 
 #include 
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
 # include 
 # include 
 #endif
@@ -158,7 +158,7 @@ grub_util_find_root_devices_from_poolname (char *poolname)
   size_t ndevices = 0;
   size_t devices_allocated = 0;
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
   zpool_handle_t *zpool;
   libzfs_handle_t *libzfs;
   nvlist_t *config, *vdev_tree;
diff --git a/util/getroot.c b/util/getroot.c
index 086581998..75a7d5f21 100644
--- a/util/getroot.c
+++ b/util/getroot.c
@@ -47,7 +47,7 @@
 
 #include 
 
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+#ifdef USE_LIBZFS
 # include 
 # include 
 #endif
@@ -456,7 +456,7 @@ grub_util_biosdisk_is_present (const char *os_dev)
   return ret;
 }
 
-#ifdef HAVE_LIBZFS
+#ifdef USE_LIBZFS
 static libzfs_handle_t *__libzfs_handle;
 
 static void
@@ -478,5 +478,5 @@ grub_get_libzfs_handle (void)
 
   return __libzfs_handle;
 }
-#endif /* HAVE_LIBZFS */
+#endif /* USE_LIBZFS */
 
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 07/13] gnulib: Tolerate always_inline attribute being ignored.

2023-10-08 Thread Vladimir 'phcoder' Serbinenko

From ac43147c891da23d2a851b5ceaebcecb2018ada3 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko 
Date: Thu, 24 Aug 2023 22:45:53 +0200
Subject: [PATCH 07/13] gnulib: Tolerate always_inline attribute being ignored.

It's not critical, Werror on it is inappropriate.
---
 conf/Makefile.common | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/conf/Makefile.common b/conf/Makefile.common
index f8faa92e9..b8f216f6c 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -75,7 +75,7 @@ grubconfdir = $(sysconfdir)/grub.d
 platformdir = $(pkglibdir)/$(target_cpu)-$(platform)
 starfielddir = $(pkgdatadir)/themes/starfield
 
-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion
+CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-error=attributes
 CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib
 
 CFLAGS_POSIX = -fno-builtin
-- 
2.42.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


  1   2   3   4   5   6   7   8   9   10   >