From: Pratyush Yadav
Date: Mon, 8 Jun 2020 14:10:35 +0530
Subject: [PATCH] regmap: Check for out-of-range offsets before mapping them
In-Reply-To:
References: <20200526120557.26240-1-p.yadav@ti.com>
Message-ID: <20200608084033.25zj5qobxor4mloa@ti.com>
List-Id:
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
To: u-boot@lists.denx.de
Hi Simon,
On 07/06/20 08:43PM, Simon Glass wrote:
> Hi Pratyush,
>
> On Tue, 26 May 2020 at 06:06, Pratyush Yadav wrote:
> >
> > In regmap_raw_{read,write}_range(), offsets are checked to make sure
> > they aren't out of range. But this check happens _after_ the address is
> > mapped from physical memory. Input should be sanity-checked before using
> > it. Mapping the address before validating it leaves the door open to
> > passing an invalid address to map_physmem(). So check for out of range
> > offsets _before_ mapping them.
> >
> > This fixes a segmentation fault in sandbox when -1 is used as an offset
> > to regmap_{read,write}().
> >
> > Signed-off-by: Pratyush Yadav
> > ---
> > drivers/core/regmap.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
>
> Reviewed-by: Simon Glass
Thanks.
> Please add a sandbox test to catch this problem.
The test "dm_test_devm_regmap" proposed in [0] should catch this:
ut_asserteq(-ERANGE, regmap_write(priv->cfg_regmap, -1, val));
ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, -1, &val));
[0] https://patchwork.ozlabs.org/project/uboot/patch/20200605203025.15466-9-p.yadav at ti.com/
--
Regards,
Pratyush Yadav
Texas Instruments India