From: David Timber <dxdt@dev.snart.me>
To: arnd@arndb.de, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, David Timber <dxdt@dev.snart.me>
Subject: [PATCH] drivers/char/mem.c: fix null and zero dev lseek
Date: Fri, 20 Mar 2026 13:17:22 +0900 [thread overview]
Message-ID: <20260320041722.196759-1-dxdt@dev.snart.me> (raw)
lseek() on /dev/null and /dev/zero always returns 0. This is
problematic for userland programs that detect holes and advancing
the offset by the delta (SEEK_HOLE - SEEK_DATA), which will always be
calculated as zero.
Link: https://github.com/util-linux/util-linux/pull/4132
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
drivers/char/mem.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index cca4529431f8..e2bde4ad5677 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -573,9 +573,21 @@ static ssize_t write_full(struct file *file, const char __user *buf,
* Special lseek() function for /dev/null and /dev/zero. Most notably, you
* can fopen() both devices with "a" now. This was previously impossible.
* -- SRB.
+ *
+ * For SEEK_DATA and SEEK_HOLE, return an error. Otherwise, userland conforming
+ * to the POSIX spec could end up in an infinite loop.
*/
static loff_t null_lseek(struct file *file, loff_t offset, int orig)
{
+ switch (orig) {
+ case SEEK_CUR:
+ case SEEK_SET:
+ case SEEK_END:
+ break;
+ default:
+ return -EINVAL;
+ }
+
return file->f_pos = 0;
}
--
2.53.0.1.ga224b40d3f.dirty
next reply other threads:[~2026-03-20 4:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 4:17 David Timber [this message]
2026-03-20 6:02 ` Greg KH
2026-03-22 11:52 ` [PATCH v1] " David Timber
2026-03-22 11:52 ` [PATCH] " David Timber
2026-03-22 13:20 ` David Timber
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=20260320041722.196759-1-dxdt@dev.snart.me \
--to=dxdt@dev.snart.me \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®