All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: "Cyril Hrubis" <chrubis@suse.cz>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v8 2/2] coredump02: Verify ELF structure and notes
Date: Wed, 09 Sep 2026 09:15:59 +0000	[thread overview]
Message-ID: <6aa123d0.f6835b30.6e948.fd7f@mx.google.com> (raw)
In-Reply-To: <aqAwyxICYrC487_p@yuki.lan>

Hi Cyril,

> I would have expected that the elf headers are aligned properly and
> since we loaded the whole file into aligned buffer (malloc() aligns
> properly), it should be safe to just cast the desc pointer into the
> strcut elf_prpsinfo *info = desc;  and acces info.pr_name directly from
> the buffer.

I made an analysis and I found out this is not valid.

It seems like we can't use the cast in x86_64 because it requires a
8 bytes aligned struct.

The kernel writes:

12 bytes: note header
 5 bytes: "CORE" and its ending zero
 3 bytes: padding
---
20 bytes total

Although malloc() aligns the buffer’s starting address, the descriptor
inside it is not 8-byte aligned. For example:

Buffer starts at address:    4096
Notes start at file offset:  624  (64 + 10 × 56)
First descriptor is another: 20 bytes later
Descriptor's memory address: 4740

So memory is not 8 bytes aligned and when we cast to a pointer we
might be misaligned when accessing pr_pid.

We still need memcpy(), so we make sure we are accessing the right
portion of the memory.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2026-09-09  9:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  6:26 [LTP] [PATCH v8 0/2] coredump testing suite Andrea Cervesato
2026-09-08  6:26 ` [LTP] [PATCH v8 1/2] coredump01: New core_pattern specifiers test Andrea Cervesato
2026-09-08  6:48   ` [LTP] " linuxtestproject.agent
2026-09-08 15:34   ` [LTP] [PATCH v8 1/2] " Cyril Hrubis
2026-09-08  6:26 ` [LTP] [PATCH v8 2/2] coredump02: Verify ELF structure and notes Andrea Cervesato
2026-09-08 15:59   ` Cyril Hrubis
2026-09-09  9:15     ` Andrea Cervesato via ltp [this message]

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=6aa123d0.f6835b30.6e948.fd7f@mx.google.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    --cc=chrubis@suse.cz \
    /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.