From: Andries.Brouwer@cwi.nl
To: Andries.Brouwer@cwi.nl, torvalds@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] autofs sparse fixes
Date: Mon, 29 Sep 2003 20:25:11 +0200 (MEST) [thread overview]
Message-ID: <UTC200309291825.h8TIPB318380.aeb@smtp.cwi.nl> (raw)
aeb:
/* Our write does not write to user space */
write = (ssize_t (*)(struct file *, const char *, size_t, loff_t *))
file->f_op->write;
lbt:
For cases like this, where we use a kernel pointer and do the
"set_fs(KERNEL_DS)" thing to make a user-pointer routine write
to kernel space, I suggest casting the pointer instead of
the function, along with a comment on the "set_fs()".
set_fs(KERNEL_DS);
/* This cast is legal due to the set_fs()! */
data = (const void __user *) addr;
...->write(file, data, bytes);
set_fs(old_fs);
See? That makes the cast more obvious, and it also makes it obvious
_why_ the cast from kernel->user pointer is ok in this case.
Hmm. Yes. Hmm.
I have to admit that my cast is complicated, one might even say messy,
but as always - when something seems messy it can be made to look
less so by using more lines of code. E.g.,
write = (write_to_kernel_t) file->f_op->write;
looks less intimidating, and write_to_kernel_t can be defined next to
write_proc_t that we have already.
I think I prefer two rights above two wrongs - the declaration
already gives addr the right type - it really does point to kernel space -
but we inherit an incorrect type for file->f_op->write, so have to cast
that.
Hmm. In reality maybe I have no strong feelings either way.
Will see what you do and possibly send some other version
of what you did not apply.
Andries
[Soon things get more interesting. These were the trivial cases,
with set_fs nearby and to a constant value. In other words, cases
where we know precisely what happens and only have to add a cast.
Intermezzo has a lot of code where the same code may be executed
with kernel and with user pointers.
Sendfile can use kernel or user pointers. It is declared with __user
so requires
retval = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor,
(void __user *) out_file);
(fs/read_write.c:585 -- two wrongs indeed) where the type of pointer
is implicit in the actor. Struct tty_operations has the field
int (*write)(struct tty_struct *tty, int from_user,
const unsigned char *buf, int count);
Etc. Lots of places where static markup does not suffice to show
which pointers point to user space. Pity. That diminishes the value
of __user markup greatly.]
next reply other threads:[~2003-09-29 18:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-29 18:25 Andries.Brouwer [this message]
2003-09-30 23:54 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2003-09-28 23:25 Andries.Brouwer
2003-09-29 16:44 ` Linus Torvalds
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=UTC200309291825.h8TIPB318380.aeb@smtp.cwi.nl \
--to=andries.brouwer@cwi.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.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®