On Sun, Dec 09, 2018 at 11:58:04AM +0200, Leon Romanovsky wrote: > From: Michael Guralnik <michaelgur@xxxxxxxxxxxx> > > Add a helper to zero fill fields before copying data to UVERBS_ATTR_STRUCT. > > As UVERBS_ATTR_STRUCT can be used as an extensible struct, we want to make > sure that if the user supplies us with a struct that has new fields that > we are not aware of, we return them zeroed to the user. > > This helper should be used when using UVERBS_ATTR_STRUCT for an extendable > data structure and there is a need to make sure that extended members of > the struct, that the kernel doesn't handle, are returned zeroed to the > user. This is needed due to the fact that UVERBS_ATTR_STRUCT allows > non-zero values for members after 'last' member. > > Signed-off-by: Michael Guralnik <michaelgur@xxxxxxxxxxxx> > Reviewed-by: Majd Dibbiny <majd@xxxxxxxxxxxx> > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> > drivers/infiniband/core/uverbs_ioctl.c | 11 +++++++++++ > include/rdma/uverbs_ioctl.h | 7 +++++++ > 2 files changed, 18 insertions(+) > > diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c > index 3cc46447240e..8c81ff698052 100644 > +++ b/drivers/infiniband/core/uverbs_ioctl.c > @@ -751,3 +751,14 @@ int _uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle, > return 0; > } > EXPORT_SYMBOL(_uverbs_get_const); > + > +int uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle, > + size_t idx, const void *from, size_t size) > +{ > + const struct uverbs_attr *attr = uverbs_attr_get(bundle, idx); > + > + if (clear_user(u64_to_user_ptr(attr->ptr_attr.data), > + attr->ptr_attr.len)) Oh this is the function Doug and I were looking for in that other thread.. Can you send a patch to make uverbs_response() use it? Thanks, Jason