From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753137AbbCJOAF (ORCPT ); Tue, 10 Mar 2015 10:00:05 -0400 Received: from mail-qc0-f179.google.com ([209.85.216.179]:38013 "EHLO mail-qc0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752054AbbCJOAC convert rfc822-to-8bit (ORCPT ); Tue, 10 Mar 2015 10:00:02 -0400 Message-ID: <54FEF8C7.7050906@gmail.com> Date: Tue, 10 Mar 2015 09:59:35 -0400 From: Dan Rosenberg User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Fam Zheng , linux-kernel@vger.kernel.org CC: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.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@vger.kernel.org, linux-api@vger.kernel.org, Josh Triplett , "Michael Kerrisk (man-pages)" , Paolo Bonzini , Omar Sandoval , Jonathan Corbet , shane.seymour@hp.com Subject: Re: [PATCH v4 4/9] epoll: Add implementation for epoll_ctl_batch References: <1425952155-27603-1-git-send-email-famz@redhat.com> <1425952155-27603-5-git-send-email-famz@redhat.com> In-Reply-To: <1425952155-27603-5-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@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.