Skip to content

Commit 301a721

Browse files
matanb10dledford
authored andcommitted
IB/core: Add ib_is_udata_cleared
Extending core and vendor verb commands require us to check that the unknown part of the user's given command is all zeros. Adding ib_is_udata_cleared in order to do so. Signed-off-by: Matan Barak <[email protected]> Reviewed-by: Haggai Eran <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 972ecb8 commit 301a721

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

include/rdma/ib_verbs.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include <uapi/linux/if_ether.h>
5454
#include <net/ipv6.h>
5555
#include <net/ip.h>
56+
#include <linux/string.h>
57+
#include <linux/slab.h>
5658

5759
#include <linux/atomic.h>
5860
#include <linux/mmu_notifier.h>
@@ -1922,6 +1924,31 @@ static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len
19221924
return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
19231925
}
19241926

1927+
static inline bool ib_is_udata_cleared(struct ib_udata *udata,
1928+
size_t offset,
1929+
size_t len)
1930+
{
1931+
const void __user *p = udata->inbuf + offset;
1932+
bool ret = false;
1933+
u8 *buf;
1934+
1935+
if (len > USHRT_MAX)
1936+
return false;
1937+
1938+
buf = kmalloc(len, GFP_KERNEL);
1939+
if (!buf)
1940+
return false;
1941+
1942+
if (copy_from_user(buf, p, len))
1943+
goto free;
1944+
1945+
ret = !memchr_inv(buf, 0, len);
1946+
1947+
free:
1948+
kfree(buf);
1949+
return ret;
1950+
}
1951+
19251952
/**
19261953
* ib_modify_qp_is_ok - Check that the supplied attribute mask
19271954
* contains all required attributes and no attributes not allowed for

0 commit comments

Comments
 (0)