Received: by 10.223.176.5 with SMTP id f5csp3419192wra; Mon, 29 Jan 2018 12:55:11 -0800 (PST) X-Google-Smtp-Source: AH8x227zzkjwO69NdHWK6XGqmBb0EU/eFAi3XBx9bZzk881h/tQ3j7i4mEbgakQly9yrO7qZbWDt X-Received: by 10.98.157.211 with SMTP id a80mr27877314pfk.242.1517259311685; Mon, 29 Jan 2018 12:55:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517259311; cv=none; d=google.com; s=arc-20160816; b=AHG0iGrOrHpgD0z/Che88rZz37ovSEvBjnmjcqN5kszfxVi+7+An+S+rwLtXoo9eky 58y1dSsTo7KAZecGvOMSbzHL0sT5sbfm+yvZmGcm6Cr8v74w/xqDdlcPsNjeobCZl4Pq aYA5Gf1752t8/G4zygpesmtIhqClPF0LuiwU28AvJT3plvW4KqqaBYM9KMVYHt02wG+p bbipIMLkjDrJLaoHZb81GxRrUopjTDDGwzBIeLsXMBleMVhjENDSvJ5zbmNmxFKh+t7J afVOEAEWwrkJww6ggiP/qRcZYLS07Np6EixB6QG6kHD6EUy8/Up0ZDOgVKon7cfGuumE oqKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=boHSCSrR6DybegwJpLpO0bACPNpQ6pxc7EiQhrFW3W4=; b=CRZvfwkz2FBx62zDP+ywN3l+aFsUTQVU++egux7Ssh4yUuL95vsQALwISIJWazuIXA gLHxGXs5v44GFOEWyFLRAL/juD0deKRu8o0XiB+EnPvwsyszxqxdSoEkRoUV0SDkZudw Gu2SYaThgEJwd0xLCRrkFlynXUIuKS9WGYAdK+jPVA3LRH5wst37uzcB5YMG7l7uWjCz cQU5F24xdawixnb/QToiozkSYliIjTnVMKn0mUV/yGTZnhUmLgR/hhioTkMPDgh2paa3 EsYVSXW0EY8nsNrIrIXVVy5zACpLmWg0bi7u1p54DskFZOEUoQLWkMxxFNPFg7GUVimN +hXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k29si531919pfj.228.2018.01.29.12.54.56; Mon, 29 Jan 2018 12:55:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751647AbeA2Uyf (ORCPT + 99 others); Mon, 29 Jan 2018 15:54:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56400 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752819AbeA2UKI (ORCPT ); Mon, 29 Jan 2018 15:10:08 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1CE7C2F2A; Mon, 29 Jan 2018 13:02:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlastimil Babka , Michal Hocko , Alexander Viro , Eric Dumazet , David Laight , Hillf Danton , Nicholas Piggin , Jason Baron , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 20/74] fs/select: add vmalloc fallback for select(2) Date: Mon, 29 Jan 2018 13:56:25 +0100 Message-Id: <20180129123848.523118725@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vlastimil Babka commit 2d19309cf86883f634a4f8ec55a54bda87db19bf upstream. The select(2) syscall performs a kmalloc(size, GFP_KERNEL) where size grows with the number of fds passed. We had a customer report page allocation failures of order-4 for this allocation. This is a costly order, so it might easily fail, as the VM expects such allocation to have a lower-order fallback. Such trivial fallback is vmalloc(), as the memory doesn't have to be physically contiguous and the allocation is temporary for the duration of the syscall only. There were some concerns, whether this would have negative impact on the system by exposing vmalloc() to userspace. Although an excessive use of vmalloc can cause some system wide performance issues - TLB flushes etc. - a large order allocation is not for free either and an excessive reclaim/compaction can have a similar effect. Also note that the size is effectively limited by RLIMIT_NOFILE which defaults to 1024 on the systems I checked. That means the bitmaps will fit well within single page and thus the vmalloc() fallback could be only excercised for processes where root allows a higher limit. Note that the poll(2) syscall seems to use a linked list of order-0 pages, so it doesn't need this kind of fallback. [eric.dumazet@gmail.com: fix failure path logic] [akpm@linux-foundation.org: use proper type for size] Link: http://lkml.kernel.org/r/20160927084536.5923-1-vbabka@suse.cz Signed-off-by: Vlastimil Babka Acked-by: Michal Hocko Cc: Alexander Viro Cc: Eric Dumazet Cc: David Laight Cc: Hillf Danton Cc: Nicholas Piggin Cc: Jason Baron Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/select.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/fs/select.c +++ b/fs/select.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -550,7 +551,7 @@ int core_sys_select(int n, fd_set __user fd_set_bits fds; void *bits; int ret, max_fds; - unsigned int size; + size_t size, alloc_size; struct fdtable *fdt; /* Allocate small arguments on the stack to save memory and be faster */ long stack_fds[SELECT_STACK_ALLOC/sizeof(long)]; @@ -577,7 +578,14 @@ int core_sys_select(int n, fd_set __user if (size > sizeof(stack_fds) / 6) { /* Not enough space in on-stack array; must use kmalloc */ ret = -ENOMEM; - bits = kmalloc(6 * size, GFP_KERNEL); + if (size > (SIZE_MAX / 6)) + goto out_nofds; + + alloc_size = 6 * size; + bits = kmalloc(alloc_size, GFP_KERNEL|__GFP_NOWARN); + if (!bits && alloc_size > PAGE_SIZE) + bits = vmalloc(alloc_size); + if (!bits) goto out_nofds; } @@ -614,7 +622,7 @@ int core_sys_select(int n, fd_set __user out: if (bits != stack_fds) - kfree(bits); + kvfree(bits); out_nofds: return ret; }