From patchwork Fri Nov 6 03:42:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 7566301 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 54EB0C05C6 for ; Fri, 6 Nov 2015 03:43:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73DBA20851 for ; Fri, 6 Nov 2015 03:43:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 934D620850 for ; Fri, 6 Nov 2015 03:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031407AbbKFDnT (ORCPT ); Thu, 5 Nov 2015 22:43:19 -0500 Received: from mail-io0-f172.google.com ([209.85.223.172]:34163 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965560AbbKFDnT (ORCPT ); Thu, 5 Nov 2015 22:43:19 -0500 Received: by iody8 with SMTP id y8so111964937iod.1; Thu, 05 Nov 2015 19:43:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ms37p6Ij4pHHeIKZsQJnXxakiGLOEBb9Q2MHo3C68Wc=; b=io8lpJJLASWm0R64WYT0m+vGgcrfjkFLm9MlHWvFtrPokiP9PtkfrWE2OwzFLULKA8 bY2cdG9KFU5SHHsvi86+mWLNayyCYV9Ic5p8tAGF97kP+c2iCKGjIQhPFodc4USj3VUV oVgRTyMID/77CptLEOhccO70+WEgZn0P2c3mR+5M8qKGv4hA38EH3cAc8qm9cYOF/68X jkkwX7aogAd9jTz/iO75ZnZn40BmJXwLE//Z08zzJjH7O6pOZW8tIiiXynqm0THfD/W2 ksqBgs2FxKLYg9qT78LFINyHwMukc7iUhrO0BvvjOQToNPwX7qaQuRTf4nC9NnyN23xO I9aQ== X-Received: by 10.107.149.203 with SMTP id x194mr15060580iod.170.1446781398387; Thu, 05 Nov 2015 19:43:18 -0800 (PST) Received: from localhost.localdomain (c-75-72-182-251.hsd1.mn.comcast.net. [75.72.182.251]) by smtp.gmail.com with ESMTPSA id bf8sm390628igb.1.2015.11.05.19.43.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Nov 2015 19:43:17 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, edumazet@google.com, torvalds@linux-foundation.org, Eric Biggers Subject: [PATCH] vfs: clear remainder of 'full_fds_bits' in dup_fd() Date: Thu, 5 Nov 2015 21:42:48 -0600 Message-Id: <1446781368-13766-1-git-send-email-ebiggers3@gmail.com> X-Mailer: git-send-email 2.6.2 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This fixes a bug from commit f3f86e33dc3d ("vfs: Fix pathological performance case for __alloc_fd()"). Signed-off-by: Eric Biggers --- fs/file.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/file.c b/fs/file.c index 6f6eb2b..36e5103 100644 --- a/fs/file.c +++ b/fs/file.c @@ -276,7 +276,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) { struct files_struct *newf; struct file **old_fds, **new_fds; - int open_files, size, i; + int open_files, i; struct fdtable *old_fdt, *new_fdt; *errorp = -ENOMEM; @@ -357,18 +357,16 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) } spin_unlock(&oldf->file_lock); - /* compute the remainder to be cleared */ - size = (new_fdt->max_fds - open_files) * sizeof(struct file *); - - /* This is long word aligned thus could use a optimized version */ - memset(new_fds, 0, size); - + /* clear the remainder if needed */ if (new_fdt->max_fds > open_files) { - int left = (new_fdt->max_fds - open_files) / 8; + int left = new_fdt->max_fds - open_files; int start = open_files / BITS_PER_LONG; - memset(&new_fdt->open_fds[start], 0, left); - memset(&new_fdt->close_on_exec[start], 0, left); + memset(new_fds, 0, left * sizeof(struct file *)); + memset(&new_fdt->open_fds[start], 0, left / 8); + memset(&new_fdt->close_on_exec[start], 0, left / 8); + memset(&new_fdt->full_fds_bits[BITBIT_NR(open_files)], 0, + BITBIT_SIZE(new_fdt->max_fds) - BITBIT_SIZE(open_files)); } rcu_assign_pointer(newf->fdt, new_fdt);