From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Al Viro <viro@ZenIV.linux.org.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: set_fs(KERNEL_DS) vs iovec
Date: Tue, 22 May 2018 15:08:35 +1000 [thread overview]
Message-ID: <8c7ac8af210606f2e4be4bfbb0b2506be53b60e3.camel@kernel.crashing.org> (raw)
Hi guys !
I was helping with a small driver when I stumbled upon a comment from a
reviwer pointing to an old lwn article talking about deprecating set_fs
due to security concerns:
https://lwn.net/Articles/722267/
Now, this is a very simple driver running on a small/slow ARM SoC,
which reads from a FIFO and writes into a destination buffer.
It provides 2 interfaces, a userspace one (read syscall) and an in-
kernel one since some other kernel drivers use it as a transport.
My existing implementation uses the good old construct of doing
put_user() in the low level FIFO pumping code, and have the in-kernel
API do:
old_fs = get_fs();
set_fs(KERNEL_DS);
rc = __sbefifo_submit(sbefifo, command, cmd_len,
response, resp_len);
set_fs(old_fs);
Which is simple, turns into fairly efficient code on that simple
device, and doesn't seem to have security issues...
That said, following the advice in that article, I tried to look at the
iovec stuff and noticed:
- The APIs are almost entirely undocumented (or did I look in the
wrong place ?)
- The code in lib/iov_iter.c is rather ... unreadable
- It's also significantly more complex, thus would probably result in
a slower driver (remember: small SoC). It's quite overkill for my
simple use case.
- There are very few users, set_fs(KERNEL_DS) is still the most common
method used by drivers.
Hence my question: Is is still acceptable these days to use
set_fs(KERNEL_DS) for simple cases like this ? Or is it really
deprecated and all new users should use the iovec's ?
Cheers,
Ben.
next reply other threads:[~2018-05-22 5:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 5:08 Benjamin Herrenschmidt [this message]
2018-05-22 10:20 ` set_fs(KERNEL_DS) vs iovec Christoph Hellwig
2018-05-22 12:44 ` Benjamin Herrenschmidt
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=8c7ac8af210606f2e4be4bfbb0b2506be53b60e3.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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