Skip to contentSkip to conversation

random: Forbid llseek on random chardev

PATCH In review Frederic Weisbecker 3 participants 5 messages Apr 10, 2010 Random number driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 random: Forbid llseek on random chardev

From: Arnd Bergmann <[email protected]>

Seeking on /dev/random and /dev/urandom is pointless. Using generic_file_llseek means we no longer need to take the BKL if anyone tries to seek on these.

---
 drivers/char/random.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/char/random.c +2 -0
index 2fd3d39..513c685 100644
@@ -1169,6 +1169,7 @@ const struct file_operations random_fops = {
 	.poll  = random_poll,
 	.unlocked_ioctl = random_ioctl,
 	.fasync = random_fasync,
+	.open = nonseekable_open,
 };
 
 const struct file_operations urandom_fops = {
@@ -1176,6 +1177,7 @@ const struct file_operations urandom_fops = {
 	.write = random_write,
 	.unlocked_ioctl = random_ioctl,
 	.fasync = random_fasync,
+	.open = nonseekable_open,
 };
 
 /***************************************************************
Signature · 1 line
1.6.2.3
#1 lore raw
Quoted 3 lines · Frederic Weisbecker

From: Arnd Bergmann <[email protected]>

Seeking on /dev/random and /dev/urandom is pointless.

It is indeed pointless, though that doesn't mean no one does it. Forbidding a no-op seems a rather unfriendly way to fix this.

Quoted 2 lines

Using generic_file_llseek means we no longer need to take the BKL if anyone tries to seek on these.

Comment doesn't match the patch?

Quoted 28 lines
---
 drivers/char/random.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/char/random.c +2 -0
index 2fd3d39..513c685 100644
@@ -1169,6 +1169,7 @@ const struct file_operations random_fops = {
 	.poll  = random_poll,
 	.unlocked_ioctl = random_ioctl,
 	.fasync = random_fasync,
+	.open = nonseekable_open,
 };
 
 const struct file_operations urandom_fops = {
@@ -1176,6 +1177,7 @@ const struct file_operations urandom_fops = {
 	.write = random_write,
 	.unlocked_ioctl = random_ioctl,
 	.fasync = random_fasync,
+	.open = nonseekable_open,
 };
 
 /***************************************************************
Signature · 1 line
http://selenic.com : development and support for Mercurial and Linux
#2 lore raw
Quoted 7 lines · Matt Mackall
Quoted 3 lines · Frederic Weisbecker

From: Arnd Bergmann <[email protected]>

Seeking on /dev/random and /dev/urandom is pointless.

It is indeed pointless, though that doesn't mean no one does it. Forbidding a no-op seems a rather unfriendly way to fix this.

I worried about that too. If you think that could break some user space apps, we can make it a generic_file_llseek.

Quoted 4 lines
Quoted 2 lines

Using generic_file_llseek means we no longer need to take the BKL if anyone tries to seek on these.

Comment doesn't match the patch?

Oops. I guess the patch has been updated, but not the changelog.

Some background: we are trying to remove the uses of default_llseek that use the bkl. We started with turning llseek stubs to generic_file_llseek (or non seekable open in some cases), but we are hesitating now and think about actually turn all the stubs that might need the bkl into default_llseek, and fallback to generic_file_llseek for all other stubs.

Depending on what we do I'll resend you an updated version of this patch with generic_file_llseek, or I will let the stub as is.

Thanks.

#3 lore raw
Quoted 29 lines · Frederic Weisbecker
Quoted 7 lines · Matt Mackall
Quoted 3 lines · Frederic Weisbecker

From: Arnd Bergmann <[email protected]>

Seeking on /dev/random and /dev/urandom is pointless.

It is indeed pointless, though that doesn't mean no one does it. Forbidding a no-op seems a rather unfriendly way to fix this.

I worried about that too. If you think that could break some user space apps, we can make it a generic_file_llseek.

Quoted 4 lines
Quoted 2 lines

Using generic_file_llseek means we no longer need to take the BKL if anyone tries to seek on these.

Comment doesn't match the patch?

Oops. I guess the patch has been updated, but not the changelog.

Some background: we are trying to remove the uses of default_llseek that use the bkl. We started with turning llseek stubs to generic_file_llseek (or non seekable open in some cases), but we are hesitating now and think about actually turn all the stubs that might need the bkl into default_llseek, and fallback to generic_file_llseek for all other stubs.

Quoted 3 lines

Depending on what we do I'll resend you an updated version of this patch with generic_file_llseek, or I will let the stub as is.

Sounds good.

Signature · 1 line
http://selenic.com : development and support for Mercurial and Linux
#4 lore raw
In reply to Frederic Weisbecker
Quoted 5 lines · On Saturday 10 April 2010 18:35:30 Frederic Weisbecker wrote:
Quoted 5 lines
Quoted 3 lines

Using generic_file_llseek means we no longer need to take the BKL if anyone tries to seek on these.

Comment doesn't match the patch?

Yes, my fault. The version in my series already had this problem.

Quoted 9 lines

Oops. I guess the patch has been updated, but not the changelog.

Some background: we are trying to remove the uses of default_llseek that use the bkl. We started with turning llseek stubs to generic_file_llseek (or non seekable open in some cases), but we are hesitating now and think about actually turn all the stubs that might need the bkl into default_llseek, and fallback to generic_file_llseek for all other stubs.

Quoted 3 lines

Depending on what we do I'll resend you an updated version of this patch with generic_file_llseek, or I will let the stub as is.

The noop_llseek from Jan's series seems most appropriate here.

Arnd