On Fri, Apr 17, 2020 at 11:17:18AM -0700, Matthew Wilcox wrote: > > if (error) > > - goto out; > > + goto out_free_buf; > > > > /* careful: calling conventions are nasty here */ > > I think this comment can go now ;-) It actually long predates the set_fs that was only added for BPF, and goes back to: 330d57fb98a91 ("[PATCH] Fix sysctl unregistration oops (CVE-2005-2709)") in the history.git tree. > > - } else { > > - error = table->proc_handler(table, write, buf, &count, ppos); > > - } > > + error = table->proc_handler(table, write, kbuf, &count, ppos); > > + if (error) > > + goto out_free_buf; > > + > > + error = -EFAULT; > > + if (copy_to_user(ubuf, kbuf, count)) > > + goto out_free_buf; > > Can we skip this if !write? Indeed, don't we have to in case the user has > passed a pointer to a read-only memory page? Indeed.