devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: "Pantelis Antoniou"
	<pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>,
	"Simon Glass" <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	"Boris Brezillon"
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	"Alexander Kaplan" <alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org>,
	"Thomas Petazzoni"
	<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Antoine Ténart"
	<antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	"Stefan Agner" <stefan-XLVq0VzYD2Y@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v3 6/6] libfdt: Add overlay application function
Date: Mon, 25 Jul 2016 20:20:41 +0200	[thread overview]
Message-ID: <20160725182041.GN7419@lukather> (raw)
In-Reply-To: <20160724142908.GF24621-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>

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

Hi David,

On Mon, Jul 25, 2016 at 12:29:08AM +1000, David Gibson wrote:
> > +static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
> > +				 int property)
> > +{
> > +	const char *value;
> > +	const char *label;
> > +	int len;
> > +
> > +	value = fdt_getprop_by_offset(fdto, property,
> > +				      &label, &len);
> > +	if (!value) {
> > +		if (len == -FDT_ERR_NOTFOUND)
> > +			return -FDT_ERR_INTERNAL;
> > +
> > +		return len;
> > +	}
> > +
> > +	do {
> > +		const char *prop_string = value;
> > +		const char *path, *name;
> > +		uint32_t prop_len = strnlen(value, len);
> 
> prop_len is a bad name, since it could well be less than the length of
> the whole property.
> 
> > +		uint32_t path_len, name_len;
> > +		char *sep, *endptr;
> > +		int index;
> > +		int ret;
> > +
> > +		path = prop_string;
> > +		sep = memchr(prop_string, ':', prop_len);
> > +		if (!sep || (*sep != ':'))
> > +			return -FDT_ERR_BADSTRUCTURE;
> 
> As mentioned on some of the other patches in the series, I think we
> want a new error code for bad fixup / overlay information.
> 
> > +
> > +		path_len = sep - path;
> > +		if (path_len == prop_len)
> > +			return -FDT_ERR_BADSTRUCTURE;
> 
> I'm pretty sure this is impossible if sep != NULL.
> 
> > +		name = sep + 1;
> 
> But I think the case you actually need to test for is path_len ==
> (prop_len - 1), that will occur when : is the last character.
> 
> > +		sep = memchr(name, ':', prop_len);
> > +		if (!sep || *sep != ':')
> > +			return -FDT_ERR_BADSTRUCTURE;
> 
> This still isn't quite safe.  If the property has no \0, and : is the
> last character in it, you'll access beyond the end of the property
> here.  It's probably easier if you just fail early if there is no \0 -
> that's probably easier if you use memchr(\0) instead of strnlen().
> 
> > +
> > +		name_len = sep - name;
> > +		if ((path_len + 1 + name_len) == prop_len)
> > +			return -FDT_ERR_BADSTRUCTURE;
> 
> Again, off-by-one in this test, I think.  Since there are so many
> tricky edge cases here, it might be worth making testcases for them.

What do you want here? That we move the parsing code out of that loop,
make it public and put the prototype in libfdt_internal, or that we
craft some DT that would outline all the possible issues with that
function, and just test the return code of fdt_overlay_apply?

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

  parent reply	other threads:[~2016-07-25 18:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 14:20 [PATCH v3 0/6] libfdt: Add support for device tree overlays Maxime Ripard
     [not found] ` <20160720142044.27527-1-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-20 14:20   ` [PATCH v3 1/6] libfdt: Add a subnodes iterator macro Maxime Ripard
     [not found]     ` <20160720142044.27527-2-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-21  1:59       ` David Gibson
2016-07-20 14:20   ` [PATCH v3 2/6] libfdt: Add iterator over properties Maxime Ripard
     [not found]     ` <20160720142044.27527-3-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-21  2:01       ` David Gibson
2016-07-20 14:20   ` [PATCH v3 3/6] libfdt: Add max phandle retrieval function Maxime Ripard
2016-07-20 14:20   ` [PATCH v3 4/6] libfdt: Add fdt_getprop_namelen_w Maxime Ripard
2016-07-20 14:20   ` [PATCH v3 5/6] libfdt: Add fdt_setprop_inplace_namelen_partial Maxime Ripard
2016-07-20 14:20   ` [PATCH v3 6/6] libfdt: Add overlay application function Maxime Ripard
     [not found]     ` <20160720142044.27527-7-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-24 14:29       ` David Gibson
     [not found]         ` <20160724142908.GF24621-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-25 18:20           ` Maxime Ripard [this message]
2016-07-26  0:18             ` David Gibson
     [not found]               ` <20160726001859.GF17429-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-26  6:16                 ` Maxime Ripard
2016-07-26 14:09                   ` David Gibson

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=20160725182041.GN7419@lukather \
    --to=maxime.ripard-wi1+55scjutkeb57/3fjtnbpr1lh4cv8@public.gmane.org \
    --cc=alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org \
    --cc=antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=stefan-XLVq0VzYD2Y@public.gmane.org \
    --cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).