All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve French <smfrench@gmail.com>
To: Ronnie Sahlberg <lsahlber@redhat.com>
Cc: linux-cifs <linux-cifs@vger.kernel.org>,
	Dan carpenter <dan.carpenter@oracle.com>,
	coverity-bot <keescook+coverity-bot@chromium.org>,
	Yang Yingliang <yangyingliang@huawei.com>
Subject: Re: [PATCH] cifs: set rc to -ENOENT if we can not get a dentry for the cached dir
Date: Mon, 17 Oct 2022 18:52:21 -0500	[thread overview]
Message-ID: <CAH2r5mtzftoAm147vbe80n7hWA403cT=HbfrTqa3ButyGH-Bag@mail.gmail.com> (raw)
In-Reply-To: <20221017233201.1716316-2-lsahlber@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2393 bytes --]

Lightly updated to deal with merge conflict with "cifs: use
LIST_HEAD() and list_move() to simplify code" and merged into
cifs-2.6.git for-next pending review and testing

See attached update patch.

On Mon, Oct 17, 2022 at 6:32 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> We already set rc to this return code further down in the function but
> we can set it earlier in order to suppress a smash warning.
>
> Also fix a false positive for Coverity. The reason this is a false positive is
> that this happens during umount after all files and directories have been closed
> but mosetting on ->on_list to suppress the warning.
>
> Reported-by: Dan carpenter <dan.carpenter@oracle.com>
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1525256 ("Concurrent data access violations")
> Fixes: a350d6e73f5e ("cifs: enable caching of directories for which a lease is held")
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/cached_dir.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c
> index fe88b67c863f..ffc924296e59 100644
> --- a/fs/cifs/cached_dir.c
> +++ b/fs/cifs/cached_dir.c
> @@ -253,8 +253,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
>                 dentry = dget(cifs_sb->root);
>         else {
>                 dentry = path_to_dentry(cifs_sb, path);
> -               if (IS_ERR(dentry))
> +               if (IS_ERR(dentry)) {
> +                       rc = -ENOENT;
>                         goto oshr_free;
> +               }
>         }
>         cfid->dentry = dentry;
>         cfid->tcon = tcon;
> @@ -387,13 +389,13 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
>                 list_add(&cfid->entry, &entry);
>                 cfids->num_entries--;
>                 cfid->is_open = false;
> +               cfid->on_list = false;
>                 /* To prevent race with smb2_cached_lease_break() */
>                 kref_get(&cfid->refcount);
>         }
>         spin_unlock(&cfids->cfid_list_lock);
>
>         list_for_each_entry_safe(cfid, q, &entry, entry) {
> -               cfid->on_list = false;
>                 list_del(&cfid->entry);
>                 cancel_work_sync(&cfid->lease_break);
>                 if (cfid->has_lease) {
> --
> 2.35.3
>


-- 
Thanks,

Steve

[-- Attachment #2: 0001-cifs-set-rc-to-ENOENT-if-we-can-not-get-a-dentry-for.patch --]
[-- Type: text/x-patch, Size: 1966 bytes --]

From 1b028682528ca86559cad5311eb52b57333cecf0 Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <lsahlber@redhat.com>
Date: Mon, 17 Oct 2022 18:48:26 -0500
Subject: [PATCH] cifs: set rc to -ENOENT if we can not get a dentry for the
 cached dir

We already set rc to this return code further down in the function but
we can set it earlier in order to suppress a smash warning.

Also fix a false positive for Coverity. The reason this is a false positive is
that this happens during umount after all files and directories have been closed
but mosetting on ->on_list to suppress the warning.

Reported-by: Dan carpenter <dan.carpenter@oracle.com>
Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1525256 ("Concurrent data access violations")
Fixes: a350d6e73f5e ("cifs: enable caching of directories for which a lease is held")
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/cached_dir.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c
index 8cad528a8722..20efc9e22761 100644
--- a/fs/cifs/cached_dir.c
+++ b/fs/cifs/cached_dir.c
@@ -253,8 +253,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 		dentry = dget(cifs_sb->root);
 	else {
 		dentry = path_to_dentry(cifs_sb, path);
-		if (IS_ERR(dentry))
+		if (IS_ERR(dentry)) {
+			rc = -ENOENT;
 			goto oshr_free;
+		}
 	}
 	cfid->dentry = dentry;
 	cfid->tcon = tcon;
@@ -385,13 +387,13 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
 		list_move(&cfid->entry, &entry);
 		cfids->num_entries--;
 		cfid->is_open = false;
+		cfid->on_list = false;
 		/* To prevent race with smb2_cached_lease_break() */
 		kref_get(&cfid->refcount);
 	}
 	spin_unlock(&cfids->cfid_list_lock);
 
 	list_for_each_entry_safe(cfid, q, &entry, entry) {
-		cfid->on_list = false;
 		list_del(&cfid->entry);
 		cancel_work_sync(&cfid->lease_break);
 		if (cfid->has_lease) {
-- 
2.34.1


      reply	other threads:[~2022-10-17 23:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 23:32 cifs: suppress two false positives from static analyzers Ronnie Sahlberg
2022-10-17 23:32 ` [PATCH] cifs: set rc to -ENOENT if we can not get a dentry for the cached dir Ronnie Sahlberg
2022-10-17 23:52   ` Steve French [this message]

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='CAH2r5mtzftoAm147vbe80n7hWA403cT=HbfrTqa3ButyGH-Bag@mail.gmail.com' \
    --to=smfrench@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=keescook+coverity-bot@chromium.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=yangyingliang@huawei.com \
    /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.