On Tue, Feb 09, 2021 at 08:59:38AM -0800, Jakub Kicinski wrote: > On Tue, 9 Feb 2021 08:15:11 +0200 Leon Romanovsky wrote: > > At least in my tree, we have the length check: > > 4155 if (len > sizeof(zc)) { > > 4156 len = sizeof(zc); > > 4157 if (put_user(len, optlen)) > > 4158 return -EFAULT; > > 4159 } > > > > > > Ad David wrote below, the "if (zc.reserved)" is enough. > > > > We have following options: > > 1. Old kernel that have sizeof(sz) upto .reserved and old userspace > > -> len <= sizeof(sz) - works correctly. > > 2. Old kernel that have sizeof(sz) upto .reserved and new userspace that > > sends larger struct -> "f (len > sizeof(zc))" will return -EFAULT > > Based on the code you quoted? I don't see how. Maybe I need a vacation. > put_user() just copies len back to user space after truncation.
It is me who needs to go to vacation, you are right it doesn't return for lengths larger than sizeof(zc). > > > 3. New kernel that have sizeof(sz) beyond reserved and old userspace > > -> any new added field to struct sz should be checked and anyway it is the > > same as item 1. > > 4. New kernel and new userspace > > -> standard flow.