From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v2 8/9] fs: Report errors for out-of-bounds protect operations
Date: Thu, 5 Jun 2025 09:47:12 +0200 [thread overview]
Message-ID: <20250605074713.4170334-9-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20250605074713.4170334-1-o.rempel@pengutronix.de>
The protect() function previously masked errors for out-of-bounds
requests. It would either return success for offsets already beyond
file/partition size or clamp the count for ranges extending beyond the
boundary. This behavior was introduced by commit 6815e0d05480 ("fs:
limit flash erase and protect to the partiton boundary") to address SPI
flash wrap-around issues.
This masking prevented shell commands from reporting failures for
invalid ranges, which could mislead users and scripts. For example,
underlying driver errors like -EINVAL from NVMEM were not propagated.
This patch modifies protect() to return appropriate error codes (-ENXIO
or -EINVAL) for such out-of-bounds conditions, instead of silently
succeeding or clamping.
Fixes: 6815e0d05480 ("fs: limit flash erase and protect to the partiton boundary")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
fs/fs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 465fd617c2ba..6d60a1ae918b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -652,9 +652,9 @@ int protect(int fd, size_t count, loff_t offset, int prot)
if (IS_ERR(f))
return -errno;
if (offset >= f->f_size)
- return 0;
- if (count > f->f_size - offset)
- count = f->f_size - offset;
+ return errno_set(-ENXIO);
+ if (!count || count > f->f_size - offset)
+ return errno_set(-EINVAL);
fsdrv = f->fsdev->driver;
--
2.39.5
next prev parent reply other threads:[~2025-06-05 7:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 7:47 [PATCH v2 0/9] NVMEM: Introduce write protection support Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 1/9] nvmem: Add 'protect' operation to core framework Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 2/9] nvmem: rmem: add write and protect support Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 3/9] commands: nvmem: Add support for creating dynamic rmem devices Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 4/9] regmap: Add reg_seal operation for hardware protection Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 5/9] nvmem: regmap: Implement protect operation using regmap_seal Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 6/9] nvmem: bsec: Implement NVMEM protect via regmap_seal for OTP locking Oleksij Rempel
2025-06-05 7:47 ` [PATCH v2 7/9] nvmem: rmem: generate unic device name Oleksij Rempel
2025-06-05 7:47 ` Oleksij Rempel [this message]
2025-06-05 7:47 ` [PATCH v2 9/9] test: Add pytest suite for NVMEM framework Oleksij Rempel
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=20250605074713.4170334-9-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.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