From: Boris Brezillon <boris.brezillon@bootlin.com>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: "Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Hauke Mehrtens" <hauke@hauke-m.de>,
"Richard Weinberger" <richard@nod.at>,
"Marek Vasut" <marek.vasut@gmail.com>,
linux-mtd@lists.infradead.org,
"Cyrille Pitchen" <cyrille.pitchen@wedev4u.fr>,
"Rafał Miłecki" <rafal@milecki.pl>,
"Brian Norris" <computersforpeace@gmail.com>,
"David Woodhouse" <dwmw2@infradead.org>
Subject: Re: [PATCH] mtd: bcm47xxpart: improve handling TRX partition size
Date: Sat, 12 May 2018 17:17:09 +0200 [thread overview]
Message-ID: <20180512171709.77250443@bbrezillon> (raw)
In-Reply-To: <20180512095102.58a053b9@bbrezillon>
On Sat, 12 May 2018 09:51:02 +0200
Boris Brezillon <boris.brezillon@bootlin.com> wrote:
> On Thu, 12 Apr 2018 07:24:52 +0200
> Rafał Miłecki <zajec5@gmail.com> wrote:
>
> > From: Rafał Miłecki <rafal@milecki.pl>
> >
> > When bcm47xxpart finds a TRX partition (container) it's supposed to jump
> > to the end of it and keep looking for more partitions. TRX and its
> > subpartitions are handled be a separated parser.
>
> ^ by a separate parser.
>
> No need to send a new version, I'll fix it when applying.
Applied after fixing the typo.
Thanks,
Boris
>
> >
> > The problem with old code was relying on the length specified in a TRX
> > header. That isn't reliable as TRX is commonly modified to have checksum
> > cover only non-changing subpartitions. Otherwise modifying e.g. a rootfs
> > would result in CRC32 mismatch and bootloader refusing to boot a
> > firmware.
> >
> > Fix it by trying better to figure out a real TRX size. We can securely
> > assume that TRX has to cover all subpartitions and the last one is at
> > least of a block size in size. Then compare it with a length field.
> >
> > This makes code more optimal & reliable thanks to skipping data that
> > shouldn't be parsed.
>
> I didn't check the TRX parsing logic, so I'm assuming you know what you
> do here and you've tested the modifications ;-).
>
> >
> > Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> > ---
> > drivers/mtd/bcm47xxpart.c | 22 ++++++++++++++++++----
> > 1 file changed, 18 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/mtd/bcm47xxpart.c b/drivers/mtd/bcm47xxpart.c
> > index fe2581d9d882..1f0239848ebe 100644
> > --- a/drivers/mtd/bcm47xxpart.c
> > +++ b/drivers/mtd/bcm47xxpart.c
> > @@ -186,6 +186,8 @@ static int bcm47xxpart_parse(struct mtd_info *master,
> > /* TRX */
> > if (buf[0x000 / 4] == TRX_MAGIC) {
> > struct trx_header *trx;
> > + uint32_t last_subpart;
> > + uint32_t trx_size;
> >
> > if (trx_num >= ARRAY_SIZE(trx_parts))
> > pr_warn("No enough space to store another TRX found at 0x%X\n",
> > @@ -195,11 +197,23 @@ static int bcm47xxpart_parse(struct mtd_info *master,
> > bcm47xxpart_add_part(&parts[curr_part++], "firmware",
> > offset, 0);
> >
> > - /* Jump to the end of TRX */
> > + /*
> > + * Try to find TRX size. The "length" field isn't fully
> > + * reliable as it could be decreased to make CRC32 cover
> > + * only part of TRX data. It's commonly used as checksum
> > + * can't cover e.g. ever-changing rootfs partition.
> > + * Use offsets as helpers for assuming min TRX size.
> > + */
> > trx = (struct trx_header *)buf;
> > - offset = roundup(offset + trx->length, blocksize);
> > - /* Next loop iteration will increase the offset */
> > - offset -= blocksize;
> > + last_subpart = max3(trx->offset[0], trx->offset[1],
> > + trx->offset[2]);
> > + trx_size = max(trx->length, last_subpart + blocksize);
> > +
> > + /*
> > + * Skip the TRX data. Decrease offset by block size as
> > + * the next loop iteration will increase it.
> > + */
> > + offset += roundup(trx_size, blocksize) - blocksize;
> > continue;
> > }
> >
>
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2018-05-12 15:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 5:24 [PATCH] mtd: bcm47xxpart: improve handling TRX partition size Rafał Miłecki
2018-05-12 7:51 ` Boris Brezillon
2018-05-12 15:17 ` Boris Brezillon [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=20180512171709.77250443@bbrezillon \
--to=boris.brezillon@bootlin.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=hauke@hauke-m.de \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
--cc=zajec5@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox