All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Schmitt" <scdbackup@gmx.net>
To: grub-devel@gnu.org
Cc: fengtao40@huawei.com,dkiper@net-space.pl,yanan@huawei.com
Subject: Re: Possible memory fault in fs/iso9660 (correction)
Date: Tue, 29 Nov 2022 19:47:22 +0100	[thread overview]
Message-ID: <50363882005823433@scdbackup.webframe.org> (raw)
In-Reply-To: <3ad04de3-aece-fa0a-278f-cf30210722b4@huawei.com>

Hi,

Fengtao wrote:
> I think:
>         (char *) entry < (char *) sua + sua_size - 3 && entry->len > 0
> is ok, or:
>         (char *) entry <= (char *) sua + sua_size - 4 && entry->len > 0

"4" would be overdone. There are SUSP and RRIP entries of length 4,
which would be ignored if appearing at the end of the SUSP controlled area.


> I am also not familiar with ISO format.

I seem to be the last active programmer on that topic.

As stated on 24 Nov, i see other potential memory faults in the code of
grub-core/fs/iso9660.c if the ISO image contains incorrect SUSP entries.

---------------------------------------------------------------------------

I began to hack an ISO image so that it shows non-SUSP data after the
SUSP data. (See below.)

But now i am having noob problems with grub-fstest.

I pulled the source from git://git.savannah.gnu.org/grub on Debian 11 and
built it as prescribed in INSTALL.
Nevertheless grub-fstest does not show a memory fault with:

  valgrind ./grub-fstest /dvdbuffer/grub_test_non_susp.iso ls /

gdb says that the execution enters grub_iso9660_susp_iterate()
  Breakpoint 1, 0x000055555557dde4 in grub_iso9660_susp_iterate ()
but gives no further information, because
  (No debugging symbols found in ./grub-fstest)

Next i tried to insert visible messages into grub_iso9660_susp_iterate():
  grub_error (GRUB_ERR_BAD_NUMBER, "grub_iso9660_susp_iterate: called");
  ...
  grub_error (GRUB_ERR_BAD_NUMBER, "grub_iso9660_susp_iterate: before loop");
  ...
    grub_error (GRUB_ERR_BAD_NUMBER,
                "grub_iso9660_susp_iterate: sua + sua_size - entry = %ld",
                (long int) ((char *) sua + sua_size - (char *) entry));
I do not see any of them when running with above arguments.

So how can i make grub-core/fs/iso9660.c debuggable or let it emit visible
messages ?

---------------------------------------------------------------------------
The test ISO is made by these commands in bash:

  # Create an ISO with a playground of SUSP data.
  echo dummy >dummy_file
  test -e grub_test_non_susp.iso && rm grub_test_non_susp.iso
  xorriso \
     -xattr on \
     -outdev grub_test_non_susp.iso \
     -map dummy_file /dummy_file \
     -setfattr user.x y /dummy_file -- \
     -padding 0

  # Search for the AL entry of length 0x0c which holds attribute user.x.
  # (AL is the entry type of my invention AAIP. It gets ignored by all
  #  readers except xorriso. So it is a good playground for manipulations.)
  # (There is also another AL entry of size 0x10 in the CE area of the root
  #  directory.)
  al=$(grep -a -o -b 'AL'$'\x0c'$'\x01' grub_test_non_susp.iso | \
       sed -e 's/:/ /' | awk '{print $1}')

  # Replace length field value 0x0c by 0x0a.
  # This leaves the last 2 bytes of the AL entry as trailing non-SUSP data
  # in the System Use field of the directory entry.
  al_length_offset=$(expr $al + 2)
  echo $'\x0a' | \
    dd of=grub_test_non_susp.iso \
       bs=1 count=1 seek="$al_length_offset" conv=notrunc

Inspection by a hex dumper shows that the AL entry indeed announces the
desired (short) length of 10.

---------------------------------------------------------------------------

I also learned by doing and then by reading specs that a padding byte after
the System Use data is present if needed to get an even number of bytes
as size of the directory record.

This could explain the existing "- 1" in GRUB's code.

Above ISO is supposed to show 3 non-SUSP bytes at the end of the System Use
field: 2 from my dd manipulation, 1 as regular padding.


Have a nice day :)

Thomas



  parent reply	other threads:[~2022-11-29 18:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19 12:38 Possible memory fault in fs/iso9660 Thomas Schmitt
2022-11-19 12:57 ` Possible memory fault in fs/iso9660 (correction) Thomas Schmitt
2022-11-24 13:17   ` Daniel Kiper
2022-11-24 15:16     ` Thomas Schmitt
2022-11-29  9:32       ` Fengtao (fengtao, Euler)
2022-11-29 14:26         ` Daniel Kiper
2022-11-29 19:12           ` Thomas Schmitt
2022-11-29 18:47         ` Thomas Schmitt [this message]
2022-12-12 14:32           ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50363882005823433@scdbackup.webframe.org \
    --to=scdbackup@gmx.net \
    --cc=dkiper@net-space.pl \
    --cc=fengtao40@huawei.com \
    --cc=grub-devel@gnu.org \
    --cc=yanan@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.