From: Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
To: Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Lingzhu Xiang <lxiang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Matthew Garrett <mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>,
Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>,
Matt Fleming
<matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 2/2] efivarfs: guid part of filenames are case-insensitive
Date: Mon, 11 Feb 2013 15:22:21 +0000 [thread overview]
Message-ID: <20130211152221.GL4503@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1360592935-26026-3-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
On Mon, Feb 11, 2013 at 02:28:55PM +0000, Matt Fleming wrote:
> From: Matt Fleming <matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> It makes no sense to treat the following filenames as unique,
>
> VarName-abcdefab-abcd-abcd-abcd-abcdefabcdef
> VarName-ABCDEFAB-ABCD-ABCD-ABCD-ABCDEFABCDEF
> VarName-ABcDEfAB-ABcD-ABcD-ABcD-ABcDEfABcDEf
> VarName-aBcDEfAB-aBcD-aBcD-aBcD-aBcDEfaBcDEf
> ... etc ...
>
> since the guid will be converted into a binary representation, which
> has no case.
>
> Roll our own dentry operations so that we can treat the variable name
> part of filenames ("VarName" in the above example) as case-sensitive,
> but the guid portion as case-insensitive. That way, efivarfs will
> refuse to create the above files if any one already exists.
>
> Reported-by: Lingzhu Xiang <lxiang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Matthew Garrett <mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
> Cc: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> Cc: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
> Signed-off-by: Matt Fleming <matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
> drivers/firmware/efivars.c | 101 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 100 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
> index a4fa409..10088fd 100644
> --- a/drivers/firmware/efivars.c
> +++ b/drivers/firmware/efivars.c
> @@ -79,6 +79,7 @@
> #include <linux/device.h>
> #include <linux/slab.h>
> #include <linux/pstore.h>
> +#include <linux/ctype.h>
>
> #include <linux/fs.h>
> #include <linux/ramfs.h>
> @@ -1049,6 +1050,91 @@ static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
> return -EINVAL;
> };
>
> +/*
> + * Compare two efivarfs file names.
> + *
> + * An efivarfs filename is composed of two parts,
> + *
> + * 1. A case-sensitive variable name
> + * 2. A case-insensitive GUID
> + *
> + * So we need to perform a case-sensitive match on part 1 and a
> + * case-insensitive match on part 2.
> + */
> +static int efivarfs_d_compare(const struct dentry *parent, const struct inode *pinode,
> + const struct dentry *dentry, const struct inode *inode,
> + unsigned int len, const char *str,
> + const struct qstr *name)
> +{
> + const char *q;
> + int guid;
> +
> + /*
> + * If the string we're being asked to compare doesn't match
> + * the expected format return "no match".
> + */
> + if (!efivarfs_valid_name(str, len))
> + return 1;
> + if (!(q = strchr(name->name, '-')))
> + return 1;
No. Why check that again, when we'd already called ->d_hash() on the
incoming name *and* candidate dentry? And buggered off on any potential
errors.
> +
> + /* Find part 1, the variable name. */
> + guid = q - (const char *)name->name;
No need to do strchr() for that - you know that name passes
efivarfs_valid_name(), so you know how far from the end will GUID part begin.
> + /* Case-sensitive compare for the variable name */
> + if (memcmp(str, name->name, guid))
> + return 1;
> +
> + /* Case-insensitive compare for the GUID */
> + return strcasecmp(&name->name[guid], &str[guid]);
> +}
> +static int efivarfs_d_hash(const struct dentry *dentry,
> + const struct inode *inode, struct qstr *qstr)
> +{
Egads, man...
[snip the horror with copying the name]
unsigned long hash = init_name_hash();
const unsigned char *s = qstr->name;
int len = qstr->len;
if (!efivarfs_valid_name(s, len))
return -EINVAL;
while (len-- > GUID_LEN)
hash = partial_name_hash(*s++, hash);
/* GUID is case-insensitive. */
while (len--)
hash = partial_name_hash(tolower(*s++), hash);
return end_name_hash(hash);
next prev parent reply other threads:[~2013-02-11 15:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-11 14:28 [PATCH 0/2] efivarfs patch queue Matt Fleming
[not found] ` <1360592935-26026-1-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-02-11 14:28 ` [PATCH 1/2] efivarfs: Validate filenames much more aggressively Matt Fleming
[not found] ` <1360592935-26026-2-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-02-11 15:01 ` Al Viro
[not found] ` <20130211150109.GK4503-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2013-02-11 15:12 ` Matt Fleming
2013-02-12 12:36 ` [PATCH 1/2 v2] " Matt Fleming
2013-02-11 14:28 ` [PATCH 2/2] efivarfs: guid part of filenames are case-insensitive Matt Fleming
[not found] ` <1360592935-26026-3-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-02-11 15:22 ` Al Viro [this message]
[not found] ` <20130211152221.GL4503-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2013-02-11 15:37 ` Al Viro
2013-02-11 16:05 ` Matt Fleming
[not found] ` <20130211160557.GB26681-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-02-11 17:30 ` Al Viro
[not found] ` <20130211173057.GM4503-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2013-02-12 12:31 ` Matt Fleming
2013-02-12 12:39 ` [PATCH 2/2 v2] " Matt Fleming
[not found] ` <20130212123934.GC14790-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-02-14 16:04 ` Al Viro
[not found] ` <20130214160405.GU4503-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2013-02-14 17:11 ` Matt Fleming
[not found] ` <1360861876.24917.52.camel-ZqTwcBeJ+wsBof6jY8KHXm7IUlhRatedral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-02-14 17:55 ` Al Viro
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=20130211152221.GL4503@ZenIV.linux.org.uk \
--to=viro-3bdd1+5odreifsdqtta3olvcufugdwfn@public.gmane.org \
--cc=jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lxiang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org \
--cc=matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.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).