From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH 2/9] lib: Add a canary for guarded buffers
Date: Fri, 2 Aug 2019 06:54:10 -0400 (EDT) [thread overview]
Message-ID: <370665456.4222470.1564743250713.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20190802094708.GA27727@rei>
----- Original Message -----
> Hi!
> > > I'm aware of that. My reasoning here is that:
> > >
> > > * The end of the page is aligned by definition to 2^page_order
> > >
> > > * Any primitive types such as integer, etc. are hence aligned
> > >
> > > * Structures are padded so that the total size is multiple of
> > > the largest alignment required (because otherwise arrays of
> > > structures would end up causing unaligned access as well).
> > >
> > > That leaves out things such as buffers for direct I/O, the only way to
> > > allocate aligned buffers there is to make the size to be multiple of
> > > the block size.
> >
> > I don't have concrete example at hand, but I foggily recall
> > s390 issue from couple years back, where it didn't like odd addresses.
> > Can't recall if it was data or code pointer.
>
> Data should be fine as far as they are aligned accordingly to the type sizes.
>
> I.e. one byte acces is fine on odd addresses, otherwise most of the
> functions in string.h wouldn't work.
>
> For shorts i.e. two byte integers odd addresses are slower on x86 and
> x86_64 however does not work at all on many architectures. I remember
> that 32bit arm used to have in-kernel emulation that mostly did the
> right job but sometimes you got wrong results, so unaligned accesses are
> better to be avoided.
>
> The question is if kernel expects some alignment for buffers for things
> such as read()/write() etc. I doubt so, since that would still break
> things like write(fd, "aabbcc" + 1, 3) which I would expect is still
> valid code.
>
> Or do you have anything else in mind that may break?
I was thinking of buffers, but as it turns out the example I had in mind
was about alignment of symbols:
[ 1.888972] Loading compiled-in X.509 certificates
[ 1.888974] Problem parsing in-kernel X.509 certificate list
Dump of assembler code for function load_system_certificate_list:
0x00000000009ad2c0 <+0>: stmg %r6,%r15,72(%r15)
0x00000000009ad2c6 <+6>: larl %r13,0x64bdb8
0x00000000009ad2cc <+12>: larl %r2,0x799032
0x00000000009ad2d2 <+18>: tmll %r15,16256
0x00000000009ad2d6 <+22>: lgr %r14,%r15
0x00000000009ad2da <+26>: lay %r15,-104(%r15)
0x00000000009ad2e0 <+32>: je 0x9ad2e2 <load_system_certificate_list+34>
0x00000000009ad2e4 <+36>: stg %r14,152(%r15)
0x00000000009ad2ea <+42>: larl %r8,0x9ee28c <__setup_str_nosmp+5>
^^^^^^^^
From z/Architecture Principles of Operation SA22-7832-07:
"Only even addresses (halfword addresses) can
be generated. If an odd address is desired,
LOAD ADDRESS can be used to add one to an
address formed by LOAD ADDRESS RELATIVE
LONG."
>
> > Could we apply/enforce some minimum alignment, similar to what glibc
> > does for malloc?
>
> That would be against the purpose of this patchset, i.e. catching
> off-by-one bugs, since the page boundary would be a few bytes after the
> end of the buffer in some cases. Well I guess that most of the
> allocations would be as a matter of fact aligned and even these that are
> not could be easily fixed by choosing buffers that are multiples of
> four.
OK, that's a fair point.
>
> I would be fine with aligning the buffers for architectures that turn
> out to be problematic if we find some. However I would like to avoid to
> "just in case" modifications.
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
next prev parent reply other threads:[~2019-08-02 10:54 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 9:26 [LTP] [RFC PATCH 0/9] Introduce guarded buffers Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 1/9] lib: Add support for " Cyril Hrubis
2019-08-01 10:39 ` Jan Stancek
2019-08-01 11:45 ` Cyril Hrubis
2019-08-02 14:03 ` Richard Palethorpe
2019-08-02 13:57 ` Richard Palethorpe
2019-08-02 13:59 ` Cyril Hrubis
2019-08-02 14:23 ` Cyril Hrubis
2019-08-02 14:36 ` Richard Palethorpe
2019-08-02 14:50 ` Cyril Hrubis
2019-08-02 14:20 ` Cyril Hrubis
2019-08-03 12:55 ` Li Wang
2019-08-06 7:36 ` Richard Palethorpe
2019-08-06 9:03 ` Richard Palethorpe
2019-08-08 9:06 ` Cyril Hrubis
2019-08-08 9:13 ` Li Wang
2019-08-08 15:41 ` Richard Palethorpe
2019-08-01 9:26 ` [LTP] [RFC PATCH 2/9] lib: Add a canary " Cyril Hrubis
2019-08-01 10:43 ` Jan Stancek
2019-08-01 11:54 ` Cyril Hrubis
2019-08-01 16:32 ` Jan Stancek
2019-08-02 9:47 ` Cyril Hrubis
2019-08-02 10:54 ` Jan Stancek [this message]
2019-08-03 13:02 ` Li Wang
2019-08-08 9:27 ` Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 3/9] syscalls/preadv01: Make use of " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 4/9] syscalls/accept4_01: " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 5/9] syscalls/add_key04: " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 6/9] syscalls/adjtimex: " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 7/9] syscalls/clock_getres01: " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 8/9] syscalls/clock_settime01: " Cyril Hrubis
2019-08-01 9:26 ` [LTP] [RFC PATCH 9/9] syscalls/sendmmsg01: " Cyril Hrubis
2019-08-06 9:47 ` [LTP] [PATCH v3 0/4] eBPF tests using guarded buffers API Richard Palethorpe
2019-08-06 9:47 ` [LTP] [PATCH v3 1/4] BPF: Essential headers for map creation Richard Palethorpe
2019-08-06 9:47 ` [LTP] [PATCH v3 2/4] BPF: Sanity check creating and updating maps Richard Palethorpe
2019-08-06 9:47 ` [LTP] [PATCH v3 3/4] BPF: Essential headers for a basic program Richard Palethorpe
2019-08-06 9:47 ` [LTP] [PATCH v3 4/4] BPF: Sanity check creating a program Richard Palethorpe
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=370665456.4222470.1564743250713.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox