From: "Sakkinen, Jarkko" <jarkko.sakkinen@intel.com>
To: Hugh Dickins <hughd@google.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jarkko Sakkinen <jarkko.sakkinen@intel.com>
Subject: Re: [PATCH] tmpfs: security xattr setting on inode creation
Date: Wed, 22 Feb 2012 19:46:03 +0200 [thread overview]
Message-ID: <CADjiTvAJEpvcpxUGz4RifY0JdW_3iBKOwb_407U94UeUQ9VKwA@mail.gmail.com> (raw)
In-Reply-To: <1329896894-7278-1-git-send-email-jarkko.sakkinen@intel.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 6899 bytes --]
Hi
Noticed some style issues that I need to fix.
On Wed, Feb 22, 2012 at 9:48 AM, Jarkko Sakkinen
<jarkko.sakkinen@intel.com> wrote:
> Adds to generic xattr support introduced in Linux 3.0 by
> implementing initxattrs callback. This enables consulting
> of security attributes from LSM and EVM when inode originally
> created.
>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@intel.com>
> ---
> Â mm/shmem.c | Â 77 +++++++++++++++++++++++++++++++++++++++++++++++------------
> Â 1 files changed, 61 insertions(+), 16 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 7a45ad0..72addf1 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1480,6 +1480,59 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
> Â /*
> Â * File creation. Allocate an inode, and we're done..
> Â */
Oops. Have to move these new functions before this
comment.
> +
> +static int shmem_xattr_alloc(size_t size, struct shmem_xattr **new_xattr)
> +{
> + Â Â Â /* wrap around? */
> + Â Â Â size_t len = sizeof(**new_xattr) + size;
> + Â Â Â if (len <= sizeof(**new_xattr))
> + Â Â Â Â Â Â Â return -ENOMEM;
> +
> + Â Â Â *new_xattr = kmalloc(len, GFP_KERNEL);
> + Â Â Â if (*new_xattr == NULL)
> + Â Â Â Â Â Â Â return -ENOMEM;
> +
> + Â Â Â (*new_xattr)->size = size;
> + Â Â Â return 0;
> +}
> +
> +static int shmem_initxattrs(struct inode *inode,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â const struct xattr *xattr_array,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â void *fs_info)
> +{
> + Â Â Â const struct xattr *xattr;
> + Â Â Â struct shmem_inode_info *info = SHMEM_I(inode);
> + Â Â Â struct shmem_xattr *new_xattr = NULL;
> + Â Â Â size_t len;
> + Â Â Â int err = 0;
> +
> + Â Â Â for (xattr = xattr_array; xattr->name != NULL; xattr++) {
> + Â Â Â Â Â Â Â err = shmem_xattr_alloc(xattr->value_len, &new_xattr);
> + Â Â Â Â Â Â Â if (err < 0)
> + Â Â Â Â Â Â Â Â Â Â Â break;
Should be "return err;" (consistency).
> +
> + Â Â Â Â Â Â Â len = strlen(xattr->name) + 1;
> + Â Â Â Â Â Â Â new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + len,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL);
> + Â Â Â Â Â Â Â if (new_xattr->name == NULL) {
> + Â Â Â Â Â Â Â Â Â Â Â kfree(new_xattr);
> + Â Â Â Â Â Â Â Â Â Â Â return -ENOMEM;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â memcpy(new_xattr->name, XATTR_SECURITY_PREFIX,
> + Â Â Â Â Â Â Â Â Â Â Â XATTR_SECURITY_PREFIX_LEN);
> + Â Â Â Â Â Â Â memcpy(new_xattr->name + XATTR_SECURITY_PREFIX_LEN,
> + Â Â Â Â Â Â Â Â Â Â Â xattr->name, len);
> + Â Â Â Â Â Â Â memcpy(new_xattr->value, xattr->value, xattr->value_len);
> +
> + Â Â Â Â Â Â Â spin_lock(&info->lock);
> + Â Â Â Â Â Â Â list_add(&new_xattr->list, &info->xattr_list);
> + Â Â Â Â Â Â Â spin_unlock(&info->lock);
> + Â Â Â }
> +
> + Â Â Â return err;
Should be "return 0;" (consistency).
> +}
> +
> Â static int
> Â shmem_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
> Â {
> @@ -1490,7 +1543,7 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
> Â Â Â Â if (inode) {
> Â Â Â Â Â Â Â Â error = security_inode_init_security(inode, dir,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &dentry->d_name,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â NULL, NULL);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &shmem_initxattrs, NULL);
> Â Â Â Â Â Â Â Â if (error) {
> Â Â Â Â Â Â Â Â Â Â Â Â if (error != -EOPNOTSUPP) {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â iput(inode);
> @@ -1630,7 +1683,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
> Â Â Â Â Â Â Â Â return -ENOSPC;
>
> Â Â Â Â error = security_inode_init_security(inode, dir, &dentry->d_name,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â NULL, NULL);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &shmem_initxattrs, NULL);
> Â Â Â Â if (error) {
> Â Â Â Â Â Â Â Â if (error != -EOPNOTSUPP) {
> Â Â Â Â Â Â Â Â Â Â Â Â iput(inode);
> @@ -1731,26 +1784,19 @@ static int shmem_xattr_get(struct dentry *dentry, const char *name,
> Â Â Â Â return ret;
> Â }
>
> -static int shmem_xattr_set(struct dentry *dentry, const char *name,
> +static int shmem_xattr_set(struct inode *inode, const char *name,
> Â Â Â Â Â Â Â Â Â Â Â Â Â const void *value, size_t size, int flags)
> Â {
> - Â Â Â struct inode *inode = dentry->d_inode;
> Â Â Â Â struct shmem_inode_info *info = SHMEM_I(inode);
> Â Â Â Â struct shmem_xattr *xattr;
> Â Â Â Â struct shmem_xattr *new_xattr = NULL;
> - Â Â Â size_t len;
> Â Â Â Â int err = 0;
>
> Â Â Â Â /* value == NULL means remove */
> Â Â Â Â if (value) {
> - Â Â Â Â Â Â Â /* wrap around? */
> - Â Â Â Â Â Â Â len = sizeof(*new_xattr) + size;
> - Â Â Â Â Â Â Â if (len <= sizeof(*new_xattr))
> - Â Â Â Â Â Â Â Â Â Â Â return -ENOMEM;
> -
> - Â Â Â Â Â Â Â new_xattr = kmalloc(len, GFP_KERNEL);
> - Â Â Â Â Â Â Â if (!new_xattr)
> - Â Â Â Â Â Â Â Â Â Â Â return -ENOMEM;
> + Â Â Â Â Â Â Â err = shmem_xattr_alloc(size, &new_xattr);
> + Â Â Â Â Â Â Â if (err < 0)
> + Â Â Â Â Â Â Â Â Â Â Â return err;
>
> Â Â Â Â Â Â Â Â new_xattr->name = kstrdup(name, GFP_KERNEL);
> Â Â Â Â Â Â Â Â if (!new_xattr->name) {
> @@ -1758,7 +1804,6 @@ static int shmem_xattr_set(struct dentry *dentry, const char *name,
> Â Â Â Â Â Â Â Â Â Â Â Â return -ENOMEM;
> Â Â Â Â Â Â Â Â }
>
> - Â Â Â Â Â Â Â new_xattr->size = size;
> Â Â Â Â Â Â Â Â memcpy(new_xattr->value, value, size);
> Â Â Â Â }
>
> @@ -1858,7 +1903,7 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
> Â Â Â Â if (size == 0)
> Â Â Â Â Â Â Â Â value = ""; Â /* empty EA, do not remove */
>
> - Â Â Â return shmem_xattr_set(dentry, name, value, size, flags);
> + Â Â Â return shmem_xattr_set(dentry->d_inode, name, value, size, flags);
>
> Â }
>
> @@ -1878,7 +1923,7 @@ static int shmem_removexattr(struct dentry *dentry, const char *name)
> Â Â Â Â if (err)
> Â Â Â Â Â Â Â Â return err;
>
> - Â Â Â return shmem_xattr_set(dentry, name, NULL, 0, XATTR_REPLACE);
> + Â Â Â return shmem_xattr_set(dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
> Â }
>
> Â static bool xattr_is_trusted(const char *name)
> --
> 1.7.5.4
>
/Jarkko
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
next prev parent reply other threads:[~2012-02-22 17:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-22 7:48 [PATCH] tmpfs: security xattr setting on inode creation Jarkko Sakkinen
2012-02-22 17:46 ` Sakkinen, Jarkko [this message]
2012-02-23 9:46 Jarkko Sakkinen
2012-02-24 8:13 ` James Morris
2012-02-25 3:19 ` Hugh Dickins
2012-02-25 7:03 ` Sakkinen, Jarkko
2012-02-27 22:46 ` Andrew Morton
2012-02-28 3:46 ` Ware, Ryan R
[not found] ` <CAGGTEhPQ6OLgqZbbAwE=3Xj8qE2iNhLOk5LdkGU13WxbY=qb2w@mail.gmail.com>
2012-02-28 4:10 ` Hugh Dickins
2012-02-28 5:51 ` Sakkinen, Jarkko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADjiTvAJEpvcpxUGz4RifY0JdW_3iBKOwb_407U94UeUQ9VKwA@mail.gmail.com \
--to=jarkko.sakkinen@intel.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).