From: Davidlohr Bueso <dave@stgolabs.net>
To: akpm@linux-foundation.org, torvalds@linux-foundation.org
Cc: manfred@colorfullife.com,
guillaume.knispel@supersonicimagine.com,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: semantics of rhashtable and sysvipc
Date: Wed, 23 May 2018 10:25:00 -0700 [thread overview]
Message-ID: <20180523172500.anfvmjtumww65ief@linux-n805> (raw)
Hi,
In sysvipc we have an ids->tables_initialized regarding the rhashtable,
introduced in 0cfb6aee70b (ipc: optimize semget/shmget/msgget for lots of keys).
It's there, specifically, to prevent nil pointer dereferences, from using an
uninitialized api. Considering how rhashtable_init() can fail (probably due to
ENOMEM, if anything), this made the overall ipc initialization capable of
failure as well. That alone is ugly, but fine, however I've spotted a few
issues regarding the semantics of tables_initialized (however unlikely they
may be):
- There is inconsistency in what we return to userspace: ipc_addid() returns
ENOSPC which is certainly _wrong_, while ipc_obtain_object_idr() returns
EINVAL.
- After we started using rhashtables, ipc_findkey() can return nil upon
!tables_initialized, but the caller expects nil for when the ipc structure
isn't found, and can therefore call into ipcget() callbacks.
I see two possible fixes. The first is to return the proper error code
if !tables_initialized, however, I'm not sure how we want to deal with the
EINVAL cases when rhashtable_init() fails. Userspace has no reason to know
about this. The ENOMEM case I guess makes sense ok.
The second alternative would be to add a BUG_ON() if the initialization fails
and we get rid of all the tables_initialized hack. I know Linus isn't fond
of this, and in the past ipc has gotten rid of BUG_ON usage in ipc because
of this. However I mention it because there are other core areas that do this
(or call panic() straightaway). Ie in networking: sock_diag_init() and
netlink_proto_init().
Thoughts?
Thanks,
Davidlohr
next reply other threads:[~2018-05-23 17:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 17:25 Davidlohr Bueso [this message]
2018-05-23 17:35 ` semantics of rhashtable and sysvipc Davidlohr Bueso
2018-05-23 18:35 ` Linus Torvalds
2018-05-23 18:31 ` Davidlohr Bueso
2018-05-23 18:52 ` Linus Torvalds
2018-05-23 18:52 ` Davidlohr Bueso
2018-05-24 17:07 ` Davidlohr Bueso
2018-05-24 17:53 ` Linus Torvalds
2018-05-24 18:51 ` Davidlohr Bueso
2018-05-24 19:17 ` 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=20180523172500.anfvmjtumww65ief@linux-n805 \
--to=dave@stgolabs.net \
--cc=akpm@linux-foundation.org \
--cc=guillaume.knispel@supersonicimagine.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).