Skip to contentSkip to conversation

Incorrect match with when != condition

Cocci Denis Efremov 2 participants 3 messages Mar 17, 2021

lore
Share & tools
lore
#0 lore 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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 12 lines · Denis Efremov

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;
@@

Quoted 6 lines

compose_entry_fh(..., int namlen, ...)

{
	...
	if (namlen == 2) {
*		dchild =@p dget_parent(dparent);
		... when != dparent == exp->ex_path.dentry

add when forall here. There does exist a path that does not contain the dparent == exp->ex_path.dentry test. That is the path that takesthe first goto out.

julia

Quoted 25 lines
	} 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 =
tmp/cocci-output-526900-b87df1-nfs3xdr.c renamed from nfsd/nfs3xdr.c +0 -0
@@ -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:

Quoted 6 lines
$ spatch --version
spatch version 1.1.0 compiled with OCaml version 4.11.1

Thanks,
Denis

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 23 lines · Julia Lawall
Quoted 12 lines · Denis Efremov

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;
@@

Quoted 6 lines

compose_entry_fh(..., int namlen, ...)

{
	...
	if (namlen == 2) {
*		dchild =@p dget_parent(dparent);
		... when != dparent == exp->ex_path.dentry
Quoted 3 lines

add when forall here. There does exist a path that does not contain the dparent == exp->ex_path.dentry test. That is the path that takesthe first goto out.

This solved the problem, thanks!
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci