mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v1] drivers/char/mem.c: fix null and zero dev lseek
Date: Sun, 22 Mar 2026 20:52:28 +0900	[thread overview]
Message-ID: <20260322115228.22413-1-dxdt@dev.snart.me> (raw)
In-Reply-To: <2026032005-porcupine-nursery-9611@gregkh>

Return -EINVAL if whence is not understood by /dev/null or /dev/zero.

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 calculated 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 | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index cca4529431f8..f0318e924db9 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -576,7 +576,19 @@ static ssize_t write_full(struct file *file, const char __user *buf,
  */
 static loff_t null_lseek(struct file *file, loff_t offset, int orig)
 {
-	return file->f_pos = 0;
+	loff_t ret;
+
+	switch (orig) {
+	case SEEK_SET:
+	case SEEK_CUR:
+	case SEEK_END:
+		ret = file->f_pos = 0;
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
 }
 
 /*
-- 
2.53.0.1.ga224b40d3f.dirty


  reply	other threads:[~2026-03-22 11:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  4:17 [PATCH] " David Timber
2026-03-20  6:02 ` Greg KH
2026-03-22 11:52   ` David Timber [this message]
2026-03-22 11:52   ` 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=20260322115228.22413-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®