From patchwork Tue Feb 16 22:49:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8333031 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 0944CC02AA for ; Tue, 16 Feb 2016 22:49:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 228E1202E5 for ; Tue, 16 Feb 2016 22:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15D23202E6 for ; Tue, 16 Feb 2016 22:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932850AbcBPWtl (ORCPT ); Tue, 16 Feb 2016 17:49:41 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:38438 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932484AbcBPWtk (ORCPT ); Tue, 16 Feb 2016 17:49:40 -0500 Received: by mail-wm0-f49.google.com with SMTP id a4so2494363wme.1 for ; Tue, 16 Feb 2016 14:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=aX/L8FAuauUAfIt27qwReVj/utrTkvTtDahZ2W0xACo=; b=PB8DcM/lgobBk6rEmXVWZ/0z2btE5ZklEVQAf5TD9ittlbV8IpjMh/hVKfvEFnQD5s eMpUBMIYKl5rvHjS292iZF0vnzuSiMhm0vxCKKBuHW3/OQIkf1TYTQzEWHgMGUhoJT/b jPDTMAw11O3B2EYyFitLa8jbY8Q6TzDOstPps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aX/L8FAuauUAfIt27qwReVj/utrTkvTtDahZ2W0xACo=; b=dfnHWeJjOIixv4H1RmkSoH1RXat6LNW6pUXMEa3xVfcAjgi3kk7O+UJ2nV/WXOpTLH 3ap89zOWbOiyGkkWWU4FQhHzhCQpgVCfH2Wx9Y2an/6JMatBiws2eUoXsU0Y+Lr0Jxiv 0wPXLS4028e/ESDAfW5G5u6q5RmQY/WfyNaSUsDllPFPVIHx4ntoykNDnqZak8EnenZH /YByv5eLKyb7l4Fejg7n8GowETfhUD2rGoKdp/H5L7E6LxU61+xox8XvX80Q7Uj51vgB 0Q71nMAvtjQav2j8tKdwKgxn01DcMBKBqOdErYi2lbQ6sOU2PZNDSnHNt6cAUIOEkdeM WG/Q== X-Gm-Message-State: AG10YOS3uRmKOhryDkrxFhcPN3W+vgVYK+NOQT0xxCbiLRkuPUcy5RkcJ+KtAiHeEZ55+Q== X-Received: by 10.28.18.85 with SMTP id 82mr23145740wms.5.1455662979120; Tue, 16 Feb 2016 14:49:39 -0800 (PST) Received: from wildmoose.dk (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id ka4sm32251893wjc.47.2016.02.16.14.49.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 14:49:38 -0800 (PST) From: Rasmus Villemoes To: Alexander Viro , Jeff Layton , "J. Bruce Fields" Cc: Rasmus Villemoes , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] vfs: make sure struct filename->iname is word-aligned Date: Tue, 16 Feb 2016 23:49:24 +0100 Message-Id: <1455662966-7977-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 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_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 I noticed that offsetof(struct filename, iname) is actually 28 on 64 bit platforms, so we always pass an unaligned pointer to strncpy_from_user. This is mostly a problem for those 64 bit platforms without HAVE_EFFICIENT_UNALIGNED_ACCESS, but even on x86_64, unaligned accesses carry a penalty, especially when done in a loop. Let's try to ensure we always pass an aligned destination pointer to strncpy_from_user. I considered making refcnt a long instead of doing the union thing, and mostly ended up tossing a coin. Signed-off-by: Rasmus Villemoes --- Cc'ing Linus, not because it's urgent in any way, but because he's usually interested in strncpy_from_user and he can probably tell me why this is completely immaterial. fs/namei.c | 2 ++ include/linux/fs.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/namei.c b/fs/namei.c index f624d132e01e..bd150fa799a2 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "internal.h" @@ -127,6 +128,7 @@ getname_flags(const char __user *filename, int flags, int *empty) struct filename *result; char *kname; int len; + BUILD_BUG_ON(offsetof(struct filename, iname) % sizeof(long) != 0); result = audit_reusename(filename); if (result) diff --git a/include/linux/fs.h b/include/linux/fs.h index ae681002100a..d522e6391855 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2245,7 +2245,10 @@ struct filename { const char *name; /* pointer to actual string */ const __user char *uptr; /* original userland pointer */ struct audit_names *aname; - int refcnt; + union { + int refcnt; + long __padding; + }; const char iname[]; };