cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: cocci@systeme.lip6.fr, Julia Lawall <julia.lawall@inria.fr>
Subject: [Cocci] Incorrect match with when != condition
Date: Wed, 17 Mar 2021 22:56:37 +0300	[thread overview]
Message-ID: <c62bd578-1f83-d876-d6f1-cc39513ecbd9@linux.com> (raw)

Hi,

I'm trying to write the check to detect the absence of commit
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=51b2ee7d006a736a9126e8111d1f24e4fd0afaa6
in kernel. The pattern can be:

@err exists@
identifier namlen, dchild, dparent, exp;
position p;
statement S;
@@

compose_entry_fh(..., int namlen, ...)
{
	...
	if (namlen == 2) {
*		dchild =@p dget_parent(dparent);
		... when != dparent == exp->ex_path.dentry
	} else S
	...
}

But unfortunately, it matches even the fixed source. I think
that condition "... when != dparent == exp->ex_path.dentry" doesn't
work as expected. Steps to reproduce:

$ cd linux # latest master branch
$ wget https://raw.githubusercontent.com/evdenis/cvehound/b2d109c959c299dce10274c1806406fc5653e5d0/cvehound/cve/CVE-2021-3178.cocci
$ spatch -D detect --cocci-file CVE-2021-3178.cocci fs/nfsd/nfs3xdr.c
fs/nfsd/nfs3xdr.c:935:10-11: ERROR: CVE-2021-3178
diff =
--- fs/nfsd/nfs3xdr.c
+++ /tmp/cocci-output-526900-b87df1-nfs3xdr.c
@@ -932,7 +932,6 @@ compose_entry_fh(struct nfsd3_readdirres
  
         if (isdotent(name, namlen)) {
                 if (namlen == 2) {
			// !!! shouldn't match because of if (dparent == exp->ex_path.dentry) goto out; check after
-                       dchild = dget_parent(dparent);
                         /*
                          * Don't return filehandle for ".." if we're at
                          * the filesystem or export root:
$ spatch --version
spatch version 1.1.0 compiled with OCaml version 4.11.1

Thanks,
Denis
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

             reply	other threads:[~2021-03-17 19:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 19:56 Denis Efremov [this message]
2021-03-17 20:32 ` [Cocci] Incorrect match with when != condition Julia Lawall
2021-03-17 20:52   ` Denis Efremov

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=c62bd578-1f83-d876-d6f1-cc39513ecbd9@linux.com \
    --to=efremov@linux.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=julia.lawall@inria.fr \
    /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).