Skip to content

Commit d4da712

Browse files
thejhgregkh
authored andcommitted
RDMA/ucma: check fd type in ucma_migrate_id()
[ Upstream commit 0d23ba6 ] The current code grabs the private_data of whatever file descriptor userspace has supplied and implicitly casts it to a `struct ucma_file *`, potentially causing a type confusion. This is probably fine in practice because the pointer is only used for comparisons, it is never actually dereferenced; and even in the comparisons, it is unlikely that a file from another filesystem would have a ->private_data pointer that happens to also be valid in this context. But ->private_data is not always guaranteed to be a valid pointer to an object owned by the file's filesystem; for example, some filesystems just cram numbers in there. Check the type of the supplied file descriptor to be safe, analogous to how other places in the kernel do it. Fixes: 88314e4 ("RDMA/cma: add support for rdma_migrate_id()") Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 60ea881 commit d4da712

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/infiniband/core/ucma.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static DEFINE_MUTEX(mut);
124124
static DEFINE_IDR(ctx_idr);
125125
static DEFINE_IDR(multicast_idr);
126126

127+
static const struct file_operations ucma_fops;
128+
127129
static inline struct ucma_context *_ucma_find_context(int id,
128130
struct ucma_file *file)
129131
{
@@ -1564,6 +1566,10 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
15641566
f = fdget(cmd.fd);
15651567
if (!f.file)
15661568
return -ENOENT;
1569+
if (f.file->f_op != &ucma_fops) {
1570+
ret = -EINVAL;
1571+
goto file_put;
1572+
}
15671573

15681574
/* Validate current fd and prevent destruction of id. */
15691575
ctx = ucma_get_ctx(f.file->private_data, cmd.id);

0 commit comments

Comments
 (0)