On Wed, Aug 02, 2023 at 04:42:10PM -0700, Nicolin Chen wrote:
On Mon, Jul 31, 2023 at 10:16:17AM -0300, Jason Gunthorpe wrote:
Ideally expanding uAPI structure size should come with new flag bits.
Flags or some kind of 'zero is the same behavior as a smaller struct' scheme.
This patch is doing the zero option:
__u32 __reserved;
- __u32 hwpt_type;
- __u32 data_len;
- __aligned_u64 data_uptr;
};
hwpt_type == 0 means default type data_len == 0 means no data data_uptr is ignored (zero is safe)
So there is no need to change it
TEST_LENGTH passing ".size = sizeof(struct _struct) - 1" expects a -EINVAL error code from "if (ucmd.user_size < op->min_size)" check in the iommufd_fops_ioctl(). This has been working when min_size is exactly the size of the structure.
When the size of the structure becomes larger than min_size, i.e. the passing size above is larger than min_size, it bypasses that min_size sanity and goes down to an ioctl handler with a potential risk. And actually, the size range can be [min_size, struct_size), making it harder for us to sanitize with the existing code.
I wonder what's the generic way of sanitizing this case? And, it seems that TEST_LENGTH needs some rework to test min_size only?
Yes, it should technically test using offsetof and a matching set of struct members.
Jason