linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* semantics of rhashtable and sysvipc
@ 2018-05-23 17:25 Davidlohr Bueso
  2018-05-23 17:35 ` Davidlohr Bueso
  2018-05-23 18:35 ` Linus Torvalds
  0 siblings, 2 replies; 10+ messages in thread
From: Davidlohr Bueso @ 2018-05-23 17:25 UTC (permalink / raw)
  To: akpm, torvalds; +Cc: manfred, guillaume.knispel, linux-api, linux-kernel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-05-24 19:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-23 17:25 semantics of rhashtable and sysvipc Davidlohr Bueso
2018-05-23 17:35 ` 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

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).