From patchwork Fri May 18 20:02:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 10412027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D15D602CB for ; Fri, 18 May 2018 20:02:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D03328918 for ; Fri, 18 May 2018 20:02:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0018728AC8; Fri, 18 May 2018 20:02:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A97BD28918 for ; Fri, 18 May 2018 20:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751452AbeERUCS (ORCPT ); Fri, 18 May 2018 16:02:18 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:52936 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751156AbeERUCR (ORCPT ); Fri, 18 May 2018 16:02:17 -0400 Received: by mail-wm0-f48.google.com with SMTP id w194-v6so15872558wmf.2; Fri, 18 May 2018 13:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=hMQpFRtSxJOUQwgpSjMqzmtbdO07J/1O4kNZ8nmAMiA=; b=S5psKwI3o7DJR6bLz01n0acVZeSYU/tcfa/nLioCSBX4xm98fif/X/0hHcjCKv43BS ZAtVBFJdVxOZC6cPcHnl63Q5/1JDXkXqhknxy1lGv++VHAf60Wk/rGz7z0wf5AsFGVN1 JnY/5tqvp3iq9xW4mHxq4AoGnLIfofHKKaFvpliT6PbEP/et8oaVlVOxZfJklvzNespi D3oWIFSRrg/kaN7XOHCVhUNptswAlqvnQfZllEK8BSlqa5NI/rHiPRTYrrB7gTvYATs6 GtVd3Dt08RnTRVj1f1i7M5mm3BAHcG4C26EFB8wVrC7SHECvO5CIdJ3dZqSF+V1nw/T2 9zjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=hMQpFRtSxJOUQwgpSjMqzmtbdO07J/1O4kNZ8nmAMiA=; b=Old+ncc64Q6U2c0YdqcDo+VwYAjouaTdkTXn2zY69vCxbbCjobkUufb+WwW8dqGltF Yi5Re7/SXrvStVa1+hvufCpfCMQJ2WI91NrnQ8WCoF1/qBkZK2p0H1pOqaj+Q1H6aIsT po9eJeSmlwczBkIwD6Wf+j7Yr5Tc8XlHxk2uW6WNg32VX5qv4v0dqWdYKfmLZFAKcv9X mcaOltywfBeffsVeng0jWoADo3QQSEiHQ/vDZAqTk9K2XC94KFEHDKXdGZm28WsFdMdH 4WKe15OYTacta323XDZPTdNWeIgeg/nhZpbzu7Eu27hwETObKEicOuhReAHvI+NsWDgW Ub5g== X-Gm-Message-State: ALKqPwcLFQ+4UgExSC0Ek9YsEgFIyOGY38bZtBwrsY3ZtRm/UuO+WUF8 sGXAqRhiJDjaPoY8/FocOg== X-Google-Smtp-Source: AB8JxZoDq2Dven7deS0Ol/P/wO8ijIFgQxNbTfJHKNephbPIifVd9OOza+d/9/6Tsgj3T4SxdGsZgg== X-Received: by 2002:a1c:e08:: with SMTP id 8-v6mr5405660wmo.67.1526673736025; Fri, 18 May 2018 13:02:16 -0700 (PDT) Received: from avx2 (nat4-minsk-pool-46-53-177-92.telecom.by. [46.53.177.92]) by smtp.gmail.com with ESMTPSA id n23-v6sm7038979wmc.23.2018.05.18.13.02.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 13:02:15 -0700 (PDT) Date: Fri, 18 May 2018 23:02:13 +0300 From: Alexey Dobriyan To: viro@zeniv.linux.org.uk Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@lst.de Subject: [PATCH -vfs] proc: don't maintain sizeof(struct proc_dir_entry) Message-ID: <20180518200213.GA8006@avx2> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Automatically cap sizeof(struct proc_dir_entry) at 192/128 bytes or 256/192 bytes if spinlock debugging/lockdep is enabled. Signed-off-by: Alexey Dobriyan --- fs/proc/generic.c | 2 +- fs/proc/inode.c | 5 +++-- fs/proc/internal.h | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -410,7 +410,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, if (!ent) goto out; - if (qstr.len + 1 <= sizeof(ent->inline_name)) { + if (qstr.len + 1 <= SIZEOF_PDE_INLINE_NAME) { ent->name = ent->inline_name; } else { ent->name = kmalloc(qstr.len + 1, GFP_KERNEL); --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -105,9 +105,10 @@ void __init proc_init_kmemcache(void) kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0, SLAB_ACCOUNT|SLAB_PANIC, NULL); proc_dir_entry_cache = kmem_cache_create_usercopy( - "proc_dir_entry", sizeof(struct proc_dir_entry), 0, SLAB_PANIC, + "proc_dir_entry", SIZEOF_PDE, 0, SLAB_PANIC, offsetof(struct proc_dir_entry, inline_name), - sizeof_field(struct proc_dir_entry, inline_name), NULL); + SIZEOF_PDE_INLINE_NAME, NULL); + BUILD_BUG_ON(sizeof(struct proc_dir_entry) >= SIZEOF_PDE); } static int proc_show_options(struct seq_file *seq, struct dentry *root) --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -61,13 +61,15 @@ struct proc_dir_entry { char *name; umode_t mode; u8 namelen; + char inline_name[]; +} __randomize_layout; + #ifdef CONFIG_64BIT -#define SIZEOF_PDE_INLINE_NAME (192-155) +#define SIZEOF_PDE (sizeof(spinlock_t) == 4 ? 192 : 256) #else -#define SIZEOF_PDE_INLINE_NAME (128-95) +#define SIZEOF_PDE (sizeof(spinlock_t) == 4 ? 128 : 192) #endif - char inline_name[SIZEOF_PDE_INLINE_NAME]; -} __randomize_layout; +#define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE - sizeof(struct proc_dir_entry)) extern struct kmem_cache *proc_dir_entry_cache; void pde_free(struct proc_dir_entry *pde);