From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Rosenberg Subject: Re: [PATCH v4 4/9] epoll: Add implementation for epoll_ctl_batch Date: Tue, 10 Mar 2015 09:59:35 -0400 Message-ID: <54FEF8C7.7050906@gmail.com> References: <1425952155-27603-1-git-send-email-famz@redhat.com> <1425952155-27603-5-git-send-email-famz@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8BIT Return-path: In-Reply-To: <1425952155-27603-5-git-send-email-famz-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Fam Zheng , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Alexander Viro , Andrew Morton , Kees Cook , Andy Lutomirski , David Herrmann , Alexei Starovoitov , Miklos Szeredi , David Drysdale , Oleg Nesterov , "David S. Miller" , Vivek Goyal , Mike Frysinger , Theodore Ts'o , Heiko Carstens , Rasmus Villemoes , Rashika Kheria , Hugh Dickins , Mathieu Desnoyers , Peter Zijlstra , linux-fsdevel List-Id: linux-api@vger.kernel.org On 03/09/2015 09:49 PM, Fam Zheng wrote: > + if (!cmds || ncmds <= 0 || ncmds > EP_MAX_BATCH) > + return -EINVAL; > + cmd_size = sizeof(struct epoll_ctl_cmd) * ncmds; > + /* TODO: optimize for small arguments like select/poll with a stack > + * allocated buffer */ > + > + kcmds = kmalloc(cmd_size, GFP_KERNEL); > + if (!kcmds) > + return -ENOMEM; You probably want to define EP_MAX_BATCH as some sane value much less than INT_MAX/(sizeof(struct epoll_ctl_cmd)). While this avoids the integer overflow from before, any user can cause the kernel to kmalloc up to INT_MAX bytes. Probably not a huge deal because it's freed at the end of the syscall, but generally not a great idea.