From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B67E2C34022 for ; Mon, 17 Feb 2020 21:50:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F08B20801 for ; Mon, 17 Feb 2020 21:50:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F08B20801 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kotori.zaitcev.us Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 126966B0003; Mon, 17 Feb 2020 16:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D7F36B0006; Mon, 17 Feb 2020 16:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F07CA6B0007; Mon, 17 Feb 2020 16:50:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id D67DC6B0003 for ; Mon, 17 Feb 2020 16:50:54 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B966D181AEF1D for ; Mon, 17 Feb 2020 21:50:54 +0000 (UTC) X-FDA: 76500964428.05.drum54_24d50e6eed949 X-HE-Tag: drum54_24d50e6eed949 X-Filterd-Recvd-Size: 4544 Received: from takane.zaitcev.us (takane.zaitcev.us [96.126.117.152]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 17 Feb 2020 21:50:52 +0000 (UTC) Received: from suzdal.zaitcev.lan (unknown [IPv6:2600:1700:1d1:f0c0::48]) by takane.zaitcev.us (Postfix) with ESMTPSA id 59B81D127; Mon, 17 Feb 2020 14:50:29 -0700 (MST) Date: Mon, 17 Feb 2020 15:50:28 -0600 From: Pete Zaitcev To: linux-mm@kvack.org Cc: Pete Zaitcev , Helge Deller , Hugh Dickins Subject: [patch] fs: Allow user.* xattr in tmpfs Message-ID: <20200217155028.632662af@suzdal.zaitcev.lan> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Not having xattr in /tmp can be worked around usually by configuring the affected software with TMPDIR=/var/tmp and the like, but I prefer having this automated, if possible. Signed-off-by: Pete Zaitcev --- fs/xattr.c | 3 +++ include/linux/xattr.h | 13 +++++++++++++ mm/shmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/fs/xattr.c b/fs/xattr.c index 90dd78f0eb27..502567a4a478 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -896,6 +896,7 @@ int simple_xattr_set(struct simple_xattrs *xattrs, const char *name, } else if (new_xattr) { list_replace(&xattr->list, &new_xattr->list); } else { + --xattrs->count; list_del(&xattr->list); } goto out; @@ -906,6 +907,7 @@ int simple_xattr_set(struct simple_xattrs *xattrs, const char *name, err = -ENODATA; } else { list_add(&new_xattr->list, &xattrs->head); + xattrs->count++; xattr = NULL; } out: @@ -988,5 +990,6 @@ void simple_xattr_list_add(struct simple_xattrs *xattrs, { spin_lock(&xattrs->lock); list_add(&new_xattr->list, &xattrs->head); + xattrs->count++; spin_unlock(&xattrs->lock); } diff --git a/include/linux/xattr.h b/include/linux/xattr.h index 6dad031be3c2..e1ed5910ef5c 100644 --- a/include/linux/xattr.h +++ b/include/linux/xattr.h @@ -67,6 +67,7 @@ static inline const char *xattr_prefix(const struct xattr_handler *handler) struct simple_xattrs { struct list_head head; spinlock_t lock; + int count; }; struct simple_xattr { @@ -83,6 +84,7 @@ static inline void simple_xattrs_init(struct simple_xattrs *xattrs) { INIT_LIST_HEAD(&xattrs->head); spin_lock_init(&xattrs->lock); + xattrs->count = 0; } /* @@ -96,6 +98,17 @@ static inline void simple_xattrs_free(struct simple_xattrs *xattrs) kfree(xattr->name); kfree(xattr); } + xattrs->count = 0; +} + +static inline int simple_xattrs_count(struct simple_xattrs *xattrs) +{ + int ret; + + spin_lock(&xattrs->lock); + ret = xattrs->count; + spin_unlock(&xattrs->lock); + return ret; } struct simple_xattr *simple_xattr_alloc(const void *value, size_t size); diff --git a/mm/shmem.c b/mm/shmem.c index c8f7540ef048..0ce17afad30e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3246,6 +3246,30 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, return simple_xattr_set(&info->xattrs, name, value, size, flags); } +static int shmem_xattr_handler_set_user(const struct xattr_handler *handler, + struct dentry *unused, struct inode *inode, + const char *name, const void *value, + size_t size, int flags) +{ + struct shmem_inode_info *info = SHMEM_I(inode); + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + + if (value) { + if (size > 8192) + return -EINVAL; + if (simple_xattrs_count(&info->xattrs) >= sbinfo->max_inodes) + return -ENOSPC; + } + name = xattr_full_name(handler, name); + return simple_xattr_set(&info->xattrs, name, value, size, flags); +} + +static const struct xattr_handler shmem_user_xattr_handler = { + .prefix = XATTR_USER_PREFIX, + .get = shmem_xattr_handler_get, + .set = shmem_xattr_handler_set_user, +}; + static const struct xattr_handler shmem_security_xattr_handler = { .prefix = XATTR_SECURITY_PREFIX, .get = shmem_xattr_handler_get, @@ -3263,6 +3287,7 @@ static const struct xattr_handler *shmem_xattr_handlers[] = { &posix_acl_access_xattr_handler, &posix_acl_default_xattr_handler, #endif + &shmem_user_xattr_handler, &shmem_security_xattr_handler, &shmem_trusted_xattr_handler, NULL