From: Michal Simek <michal.simek@amd.com>
To: Simon Glass <sjg@chromium.org>
Cc: "Kummari, Prasad" <Prasad.Kummari@amd.com>,
"u-boot@lists.denx.de" <u-boot@lists.denx.de>,
"git (AMD-Xilinx)" <git@amd.com>,
"Abbarapu, Venkatesh" <venkatesh.abbarapu@amd.com>,
"git@xilinx.com" <git@xilinx.com>,
"jagan@amarulasolutions.com" <jagan@amarulasolutions.com>,
"n-francis@ti.com" <n-francis@ti.com>,
"d-gole@ti.com" <d-gole@ti.com>, Love Kumar <love.kumar@amd.com>
Subject: Re: [PATCH] cmd: sf: prevent overwriting the reserved memory
Date: Fri, 9 Aug 2024 16:47:39 +0200 [thread overview]
Message-ID: <cab33499-07f3-4833-836c-005f3ec67fbb@amd.com> (raw)
In-Reply-To: <CAFLszTj5HW1NGaKgV51tCv-i-vSUR3btYcFbc3-WFsG8CJtFCg@mail.gmail.com>
On 8/9/24 16:44, Simon Glass wrote:
> Hi Michal,
>
> On Thu, 8 Aug 2024 at 23:39, Michal Simek <michal.simek@amd.com> wrote:
>>
>> Hi Simon,
>>
>> On 8/8/24 16:28, Simon Glass wrote:
>>> Hi Michal,
>>>
>>> On Wed, 7 Aug 2024 at 23:31, Michal Simek <michal.simek@amd.com> wrote:
>>>>
>>>>
>>>>
>>>> On 8/7/24 16:36, Simon Glass wrote:
>>>>> Hi Prasad,
>>>>>
>>>>> On Tue, 6 Aug 2024 at 23:05, Kummari, Prasad <Prasad.Kummari@amd.com> wrote:
>>>>>>
>>>>>> Hi Glass,
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Simon Glass <sjg@chromium.org>
>>>>>>> Sent: Wednesday, August 7, 2024 3:21 AM
>>>>>>> To: Kummari, Prasad <Prasad.Kummari@amd.com>
>>>>>>> Cc: u-boot@lists.denx.de; git (AMD-Xilinx) <git@amd.com>; Simek, Michal
>>>>>>> <michal.simek@amd.com>; Abbarapu, Venkatesh
>>>>>>> <venkatesh.abbarapu@amd.com>; git@xilinx.com;
>>>>>>> jagan@amarulasolutions.com; n-francis@ti.com; d-gole@ti.com
>>>>>>> Subject: Re: [PATCH] cmd: sf: prevent overwriting the reserved memory
>>>>>>>
>>>>>>> Caution: This message originated from an External Source. Use proper
>>>>>>> caution when opening attachments, clicking links, or responding.
>>>>>>>
>>>>>>>
>>>>>>> Hi Prasad,
>>>>>>>
>>>>>>> On Tue, 6 Aug 2024 at 06:08, Prasad Kummari <prasad.kummari@amd.com> wrote:
>>>>>>>>
>>>>>>>> Added LMB API to prevent SF command from overwriting reserved memory
>>>>>>>> areas. The current SPI code does not use LMB APIs for loading data
>>>>>>>> into memory addresses. To resolve this, LMB APIs were added to check
>>>>>>>> the load address of an SF command and ensure it does not overwrite
>>>>>>>> reserved memory addresses. Similar checks are used in TFTP, serial
>>>>>>>> load, and boot code to prevent overwriting reserved memory.
>>>>>>>
>>>>>>> The SPI flash may be used to load other things, not just an OS. What is your
>>>>>>> use case or problem here?
>>>>>>
>>>>>> [Prasad]: We have observed that SF command can overwrite the reserved area without throwing any errors or warnings.
>>>>>> This issue was noticed when the TF-A area is reserved in the Device Tree at address 0xf000000. The sf command is
>>>>>> corrupting the reserved area, and U-Boot relocation address too.
>>>>>>
>>>>>> EX: TF-A reserved at ddr address 0xf000000
>>>>>>
>>>>>> Versal NET> sf read 0x0f000000 0x0 0x100 ----> Overwriting reserved area.
>>>>>> device 0 offset 0x0, size 0x100
>>>>>> SF: 256 bytes @ 0x0 Read: OK
>>>>>>
>>>>>> U-boot relocation address relocaddr = 0x000000007fec2000
>>>>>>
>>>>>> Versal NET> sf write 0x0000000077ec2000 0x0 0x100 --> Overwriting reserved area.
>>>>>> device 0 offset 0x0, size 0x100
>>>>>> SF: 256 bytes @ 0x0 Written: OK
>>>>>
>>>>> Yes. There are many things which can overwrite memory, e.g. the mw
>>>>> command. It is a boot loader so this is normal.
>>>>>
>>>>> What image are you loading here?
>>>>
>>>> In spi boot it can be Kernel/rootfs but at the end of day it doesn't really matter.
>>>
>>> OK, in that case yes it should use lmb. That was the question I was
>>> trying to understand.
>>>
>>>>
>>>> We have protection for srec, fs load, tftp and wget already.
>>>>
>>>> c6855195e4b4 ("loads: Block writes into LMB reserved areas of U-Boot")
>>>> aa3c609e2be5 ("fs: prevent overwriting reserved memory")
>>>> a156c47e39ad ("tftp: prevent overwriting reserved memory")
>>>> 04592adbdb99 ("net: wget: prevent overwriting reserved memory")
>>>>
>>>> And this is just +1 patch to protect sf command that it doesn't touch reserved
>>>> location.
>>>> The same code should be used for other commands(nand, usb, etc) which loading
>>>> block of data to memory because all of them shouldn't rewrite reserved memory.
>>>>
>>>> In connection to mw/mtest/etc command protection can be also done but not sure
>>>> if this is useful because you normally not using them for booting.
>>>
>>> Exactly.
>>>
>>> I am hoping that we can pull SPI flash into bootstd...has anyone
>>> looked at that? Are you using scripts or is there a special bootmeth?
>>
>> We didn't find this issue in connection to boot. As I wrote in another reply we
>> found it via spi testcases where TF-A was placed lower in DDR and test overwrite
>> it without any other evidence. Part of the reason is that protection units are
>> not enabled to protect secure FW.
>
> Do you mean the sandbox test test/dm/sf.c ? Or something else? If the
> former, then we could mark dm_test_spi_flash() with CONFIG_SANDBOX
pytest one and I think it was this one.
https://github.com/Xilinx/u-boot-xlnx/blob/master/test/py/tests/test_spi.py
Love is working on sending this test upstream as he did with others.
Thanks,
Michal
next prev parent reply other threads:[~2024-08-09 14:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 12:07 [PATCH] cmd: sf: prevent overwriting the reserved memory Prasad Kummari
2024-08-06 21:50 ` Simon Glass
2024-08-07 5:05 ` Kummari, Prasad
2024-08-07 14:36 ` Simon Glass
2024-08-07 14:46 ` Kummari, Prasad
2024-08-07 20:53 ` Simon Glass
2024-08-08 5:31 ` Michal Simek
2024-08-08 14:28 ` Simon Glass
2024-08-09 5:39 ` Michal Simek
2024-08-09 14:44 ` Simon Glass
2024-08-09 14:47 ` Michal Simek [this message]
2024-08-09 15:58 ` Simon Glass
2024-08-26 8:48 ` Michal Simek
2024-09-01 20:10 ` Simon Glass
2024-08-07 21:12 ` Tom Rini
2024-08-08 5:35 ` Michal Simek
2024-08-08 6:22 ` Sughosh Ganu
2024-08-08 11:18 ` Michal Simek
2024-08-08 15:46 ` Tom Rini
2024-08-09 5:41 ` Michal Simek
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=cab33499-07f3-4833-836c-005f3ec67fbb@amd.com \
--to=michal.simek@amd.com \
--cc=Prasad.Kummari@amd.com \
--cc=d-gole@ti.com \
--cc=git@amd.com \
--cc=git@xilinx.com \
--cc=jagan@amarulasolutions.com \
--cc=love.kumar@amd.com \
--cc=n-francis@ti.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=venkatesh.abbarapu@amd.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