OSDN Git Service

IB/uverbs: Handle IDR and FD types without truncation
authorJason Gunthorpe <jgg@mellanox.com>
Wed, 11 Jul 2018 02:55:14 +0000 (20:55 -0600)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 25 Jul 2018 20:21:21 +0000 (14:21 -0600)
commit1250c3048cf1632f5dbb99a0242410baff67955d
treeccf33bb417e90d4b4acd8ab1a7f674beeded6983
parent3df593bfe6455f28cda879be8299b30b8601ce3b
IB/uverbs: Handle IDR and FD types without truncation

Our ABI for write() uses a s32 for FDs and a u32 for IDRs, but internally
we ended up implicitly casting these ABI values into an 'int'. For ioctl()
we use a s64 for FDs and a u64 for IDRs, again casting to an int.

The various casts to int are all missing range checks which can cause
userspace values that should be considered invalid to be accepted.

Fix this by making the generic lookup routine accept a s64, which does not
truncate the write API's u32/s32 or the ioctl API's s64. Then push the
detailed range checking down to the actual type implementations to be
shared by both interfaces.

Finally, change the copy of the uobj->id to sign extend into a s64, so eg,
if we ever wish to return a negative value for a FD it is carried
properly.

This ensures that userspace values are never weirdly interpreted due to
the various trunctations and everything that is really out of range gets
an EINVAL.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/rdma_core.c
drivers/infiniband/core/rdma_core.h
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/core/uverbs_ioctl.c
include/rdma/uverbs_std_types.h
include/rdma/uverbs_types.h
include/uapi/rdma/rdma_user_ioctl_cmds.h