All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Daniel Kiper <dkiper@net-space.pl>
Cc: grub-devel@gnu.org, Max Tottenham <mtottenh@akamai.com>
Subject: Re: [PATCH v3 2/6] json: Implement wrapping interface
Date: Tue, 26 Nov 2019 07:22:45 +0100	[thread overview]
Message-ID: <20191126062245.GA2647@ncase> (raw)
In-Reply-To: <20191118144505.wkgvcsexmhoolvn2@tomti.i.net-space.pl>

[-- Attachment #1: Type: text/plain, Size: 3828 bytes --]

On Mon, Nov 18, 2019 at 03:45:05PM +0100, Daniel Kiper wrote:
> On Fri, Nov 15, 2019 at 01:36:18PM +0100, Patrick Steinhardt wrote:
> > On Fri, Nov 15, 2019 at 12:56:40PM +0100, Daniel Kiper wrote:
> > > On Thu, Nov 14, 2019 at 02:12:39PM +0100, Patrick Steinhardt wrote:
> > > > On Thu, Nov 14, 2019 at 01:37:18PM +0100, Daniel Kiper wrote:
> > > > > On Wed, Nov 13, 2019 at 02:22:34PM +0100, Patrick Steinhardt wrote:
> > > > > > +  grub_size_t offset = 1;
> > > > > > +
> > > > > > +  if (n >= (unsigned) p->size)
> > > > >
> > > > > Should not you cast to grub_size_t? Or should n be type of p->size?
> > > > > Then you would avoid a cast.
> > > >
> > > > I find the choice of `int` quite weird on jsmn's side: there's
> > > > not a single place where the size field is getting a negative
> > > > assignment. So if you ask me, `size_t` or even just `unsigned
> > > > int` would have been the better choice here, which is why I just
> > > > opted for `grub_size_t` instead in our wrapping interface.
> > >
> > > If jsmn is using something "intish" then I think that we should use
> > > grub_ssize_t. Even if variables of a such type does not get negative
> > > values right now.
> > >
> > > > But you're right, I should cast to `grub_size_t` instead of
> > > > `unsigned` to make it a bit clearer here.
> > >
> > > ...grub_ssize_t then?
> >
> > The question is whether we want a near 1:1 mapping here or
> > something that makes sense (even though making sense is
> > subjective). I tend towards the latter one of doing the right
> > thing, mostly because I cannot make sense of a negative value
> > here. For an array, getting the -1'th child doesn't make sense,
> > so we'd have to extend the current check like following:
> >
> >     if (n < 0 || n >= p->size)
> >         return -1;
> >
> > If not checking for `n < 0`, we'd iterate children until `n`
> > overflows and reaches `-1` eventually, which would result in
> > out-of-bounds reads. So as we currently cannot make any sense of
> > that value, I tend to just say that `grub_size_t` is the correct
> > type here even though it mismatches what jsmn is doing.
> >
> > That being said, we could certainly define what a negative value
> > would do, like e.g. `-1` would get the first child from the rear
> > of the array. But that wouldn't match what jsmn uses `size` for,
> > either.
> 
> In general I agree with you. However, if jsmn uses ints for indexes
> then I would do the same in the GRUB. Otherwise, if jsmn starts using
> negative values for something we can be badly surprised. And of course
> you can ask jsmn author why he decided to use ints for indexes. I am
> also interested in hearing why he did it.
> 
> Daniel

One last pushback from my side, if you still disagree I'll change
it to move this patch seires forward.

So I dug back in history, and the original `size` field was
introduced with commit 4e869f7 (Complex types (objects and
arrays) now have also size - number of child elements,
2010-12-28). Even back then, there was not a single location
where it was assigned a negative value and nowadays there isn't
either. I've skipped through history since then and couldn't find
any instance where it could have been assigned a negative value,
so we can assume that for the last 9 years there wasn't any
reason for a signed integer as field.

So how about we keep the `grub_size_t` field, but introduce a
check in both `grub_json_getsize` and `grub_json_getchild` to
verify that the current token does not have negative size,
raising an error if it does. Like this, we are able to catch
weird behaviour of jsmn if we were to upgrade jsmn.h without
noticing the change in semantics, but still retain the saner or
at least more obvious API with `grub_size_t`.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-11-26  6:22 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-02 18:06 [PATCH 0/6] Support for LUKS2 disc encryption Patrick Steinhardt
2019-11-02 18:06 ` [PATCH 1/6] jsmn: Add JSON parser Patrick Steinhardt
2019-11-02 18:06 ` [PATCH 2/6] jsmn: Add convenience functions Patrick Steinhardt
2019-11-04 10:26   ` Max Tottenham
2019-11-04 11:00     ` Patrick Steinhardt
2019-11-04 17:42       ` Daniel Kiper
2019-11-04 18:56         ` Patrick Steinhardt
2019-11-06 11:44           ` Daniel Kiper
2019-11-06 13:08             ` Patrick Steinhardt
2019-11-13 11:16               ` Daniel Kiper
2019-11-02 18:06 ` [PATCH 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-11-04 10:30   ` Max Tottenham
2019-11-04 11:02     ` Patrick Steinhardt
2019-11-02 18:06 ` [PATCH 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-11-02 18:06 ` [PATCH 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-11-02 18:06 ` [PATCH 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-11-05  6:58 ` [PATCH v2 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-11-05  6:58   ` [PATCH v2 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-11-05  6:58   ` [PATCH v2 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-11-05  9:54     ` Max Tottenham
2019-11-05  6:58   ` [PATCH v2 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-11-06 12:04     ` Daniel Kiper
2019-11-05  6:58   ` [PATCH v2 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-11-06 12:06     ` Daniel Kiper
2019-11-05  6:58   ` [PATCH v2 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-11-06 12:22     ` Daniel Kiper
2019-11-05  6:58   ` [PATCH v2 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-11-13 13:22 ` [PATCH v3 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-11-13 13:22   ` [PATCH v3 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-11-14 10:15     ` Daniel Kiper
2019-11-13 13:22   ` [PATCH v3 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-11-14 12:37     ` Daniel Kiper
2019-11-14 13:12       ` Patrick Steinhardt
2019-11-15 11:56         ` Daniel Kiper
2019-11-15 12:36           ` Patrick Steinhardt
2019-11-18 14:45             ` Daniel Kiper
2019-11-26  6:22               ` Patrick Steinhardt [this message]
2019-11-13 13:22   ` [PATCH v3 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-11-13 13:22   ` [PATCH v3 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-11-13 13:22   ` [PATCH v3 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-11-13 13:22   ` [PATCH v3 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-11-15 12:31     ` Daniel Kiper
2019-11-15 12:55       ` Patrick Steinhardt
2019-11-18  8:45 ` [PATCH v4 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-11-18  8:45   ` [PATCH v4 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-11-18  8:45   ` [PATCH v4 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-11-18 14:14     ` Daniel Kiper
2019-11-18 15:46       ` Patrick Steinhardt
2019-11-18 16:29         ` Daniel Kiper
2019-11-18  8:45   ` [PATCH v4 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-11-18  8:45   ` [PATCH v4 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-11-18  8:45   ` [PATCH v4 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-11-18  8:45   ` [PATCH v4 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-11-18 14:33     ` Daniel Kiper
2019-11-29  6:51 ` [PATCH v5 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-11-29  6:51   ` [PATCH v5 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-11-29  6:51   ` [PATCH v5 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-11-29 15:34     ` Daniel Kiper
2019-12-06 17:24       ` Patrick Steinhardt
2019-12-08 22:49         ` Daniel Kiper
2019-11-29  6:51   ` [PATCH v5 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-11-29  6:51   ` [PATCH v5 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-11-29  6:51   ` [PATCH v5 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-11-29  6:51   ` [PATCH v5 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-12-10  9:26 ` [PATCH v6 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-12-10  9:26   ` [PATCH v6 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-12-10  9:26   ` [PATCH v6 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-12-13 18:56     ` Daniel Kiper
2019-12-10  9:26   ` [PATCH v6 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-12-10  9:26   ` [PATCH v6 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-12-10  9:26   ` [PATCH v6 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-12-10  9:26   ` [PATCH v6 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2019-12-16 12:25     ` Daniel Kiper
2019-12-16 12:37       ` Patrick Steinhardt
2019-12-16 13:05         ` Daniel Kiper
2019-12-16 13:10           ` Patrick Steinhardt
2019-12-16 13:15             ` Daniel Kiper
2019-12-20 19:33   ` [PATCH v6 0/6] Support for LUKS2 disk encryption Daniel Kiper
2019-12-27 15:08     ` Patrick Steinhardt
2019-12-27 15:18 ` [PATCH v7 " Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 1/6] json: Import upstream jsmn-1.1.0 Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 3/6] bootstrap: Add gnulib's base64 module Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 4/6] afsplitter: Move into its own module Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 5/6] luks: Move configuration of ciphers into cryptodisk Patrick Steinhardt
2019-12-27 15:18   ` [PATCH v7 6/6] disk: Implement support for LUKS2 Patrick Steinhardt
2020-01-10 14:23   ` [PATCH v7 0/6] Support for LUKS2 disk encryption 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=20191126062245.GA2647@ncase \
    --to=ps@pks.im \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    --cc=mtottenh@akamai.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.