All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luís Henriques" <lhenriques@suse.de>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jeff Layton <jlayton@kernel.org>, ceph-devel@vger.kernel.org
Subject: Re: [bug report] ceph: add support for encrypted snapshot names
Date: Wed, 06 Sep 2023 14:43:27 +0100	[thread overview]
Message-ID: <87tts7beo0.fsf@suse.de> (raw)
In-Reply-To: <940a3e16-50d2-407b-bf45-b794bad64c3f@moroto.mountain> (Dan Carpenter's message of "Wed, 6 Sep 2023 15:34:36 +0300")

Dan Carpenter <dan.carpenter@linaro.org> writes:

> Hello Luís Henriques,
>
> The patch dd66df0053ef: "ceph: add support for encrypted snapshot
> names" from Aug 25, 2022 (linux-next), leads to the following Smatch
> static checker warning:
>
> 	fs/ceph/crypto.c:252 parse_longname()
> 	warn: 'dir' is an error pointer or valid
>
> fs/ceph/crypto.c
>     211 static struct inode *parse_longname(const struct inode *parent,
>     212                                     const char *name, int *name_len)
>     213 {
>     214         struct inode *dir = NULL;
>     215         struct ceph_vino vino = { .snap = CEPH_NOSNAP };
>     216         char *inode_number;
>     217         char *name_end;
>     218         int orig_len = *name_len;
>     219         int ret = -EIO;
>     220 
>     221         /* Skip initial '_' */
>     222         name++;
>     223         name_end = strrchr(name, '_');
>     224         if (!name_end) {
>     225                 dout("Failed to parse long snapshot name: %s\n", name);
>     226                 return ERR_PTR(-EIO);
>     227         }
>     228         *name_len = (name_end - name);
>     229         if (*name_len <= 0) {
>     230                 pr_err("Failed to parse long snapshot name\n");
>     231                 return ERR_PTR(-EIO);
>     232         }
>     233 
>     234         /* Get the inode number */
>     235         inode_number = kmemdup_nul(name_end + 1,
>     236                                    orig_len - *name_len - 2,
>     237                                    GFP_KERNEL);
>     238         if (!inode_number)
>     239                 return ERR_PTR(-ENOMEM);
>     240         ret = kstrtou64(inode_number, 10, &vino.ino);
>     241         if (ret) {
>     242                 dout("Failed to parse inode number: %s\n", name);
>     243                 dir = ERR_PTR(ret);
>     244                 goto out;
>     245         }
>     246 
>     247         /* And finally the inode */
>     248         dir = ceph_find_inode(parent->i_sb, vino);
>     249         if (!dir) {
>     250                 /* This can happen if we're not mounting cephfs on the root */
>     251                 dir = ceph_get_inode(parent->i_sb, vino, NULL);
> --> 252                 if (!dir)
>     253                         dir = ERR_PTR(-ENOENT);
>
> This never returns NULL.  If it were tempted to return NULL then it
> returns -ENOMEM instead.

Oops, you're right.  But the fix should be as easy as removing that 'if'
statement and let this function simply return 'dir' as-is.

I'll send out an updated version of the patch in reply to this email.
Thanks for the report, Dan.

Cheers,
-- 
Luís

>
>     254         }
>     255         if (IS_ERR(dir))
>     256                 dout("Can't find inode %s (%s)\n", inode_number, name);
>     257 
>     258 out:
>     259         kfree(inode_number);
>     260         return dir;
>     261 }
>
> regards,
> dan carpenter

  reply	other threads:[~2023-09-06 13:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 12:34 [bug report] ceph: add support for encrypted snapshot names Dan Carpenter
2023-09-06 13:43 ` Luís Henriques [this message]
2023-09-06 13:47   ` [PATCH] " Luís Henriques
2023-09-07  0:25     ` Xiubo Li
2023-09-07  8:44       ` Luís Henriques

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=87tts7beo0.fsf@suse.de \
    --to=lhenriques@suse.de \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=jlayton@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.