Skip to contentSkip to conversation

How to match function-like macro calls, e.g. RTA_ALIGN(rta->rta_len)?

Cocci Denis Efremov 2 participants 7 messages Jan 11, 2021

lore
Share & tools
lore
#0 lore raw

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error: 
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);

What can I do to match RTA_ALIGN(...) lines?

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

#1 lore raw
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

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

#2 lore raw
Quoted 35 lines · Julia Lawall
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 4 lines
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

I use version:
spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

Maybe parsing error is fixed in new versions?

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

#3 lore raw
Quoted 43 lines · Denis Efremov
Quoted 35 lines · Julia Lawall
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 4 lines
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

Quoted 8 lines

I use version:
spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

Maybe parsing error is fixed in new versions?

I can't imagine what would cause a parsing error here. I don't see what could be special about RTA_ALIGN. Normally Coccinelle doesn't even know that it is a macro. Maybe you can try to simplify the semantic patch a little bit and see if there is some change that causes the problem to disappear? Does the problem disappear if you use a name other than RTA_ALIGN?

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

#4 lore raw
Quoted 54 lines · Julia Lawall
Quoted 50 lines · Denis Efremov
Quoted 35 lines · Julia Lawall
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 4 lines
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

I use version:
spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

Quoted 8 lines
Quoted 1 line

Maybe parsing error is fixed in new versions?

I can't imagine what would cause a parsing error here. I don't see what could be special about RTA_ALIGN. Normally Coccinelle doesn't even know that it is a macro. Maybe you can try to simplify the semantic patch a little bit and see if there is some change that causes the problem to disappear? Does the problem disappear if you use a name other than RTA_ALIGN?

Changing:

	key += RTA_ALIGN(rta->rta_len);
to:
	key = RTA_ALIGN(rta->rta_len);

makes the parsing error disappear.

Using aop instead of += leads to the same parsing error:
assignment operator aop;
key aop RTA_ALIGN(rta->rta_len);
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "test.cocci", line 14, column 10, charpos = 245 around = 'RTA_ALIGN',
whole content = * key aop RTA_ALIGN(rta->rta_len);

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

#5 lore raw
Quoted 73 lines · Denis Efremov
Quoted 54 lines · Julia Lawall
Quoted 50 lines · Denis Efremov
Quoted 35 lines · Julia Lawall
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 4 lines
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

I use version:
spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

Quoted 8 lines
Quoted 1 line

Maybe parsing error is fixed in new versions?

I can't imagine what would cause a parsing error here. I don't see what could be special about RTA_ALIGN. Normally Coccinelle doesn't even know that it is a macro. Maybe you can try to simplify the semantic patch a little bit and see if there is some change that causes the problem to disappear? Does the problem disappear if you use a name other than RTA_ALIGN?

Changing:

	key += RTA_ALIGN(rta->rta_len);
to:
	key = RTA_ALIGN(rta->rta_len);

makes the parsing error disappear.

Quoted 8 lines

Using aop instead of += leads to the same parsing error:
assignment operator aop;
key aop RTA_ALIGN(rta->rta_len);
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "test.cocci", line 14, column 10, charpos = 245 around = 'RTA_ALIGN',
whole content = * key aop RTA_ALIGN(rta->rta_len);

I assume not, but does spatch --parse-cocci test.cocci work?

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

#6 lore raw
Quoted 86 lines · Julia Lawall
Quoted 73 lines · Denis Efremov
Quoted 54 lines · Julia Lawall
Quoted 50 lines · Denis Efremov
Quoted 35 lines · Julia Lawall
Quoted 31 lines · Denis Efremov

Hi,

Let's suppose I want to match otx_cpt_aead_cbc_aes_sha_setkey() function from drivers/crypto/marvell/octeontx/otx_cptvf_algs.c file (linux kernel).

My pattern:
@exists@
identifier rta, param, key, keylen;
position p;
@@

otx_cpt_aead_cbc_aes_sha_setkey(...,
unsigned char *key, unsigned int keylen)

{
	...
*	if (RTA_PAYLOAD(rta) < sizeof(*param))@p
		goto badkey;
	...
*	key += RTA_ALIGN(rta->rta_len);
*	keylen -= RTA_ALIGN(rta->rta_len);
	...
}
$ spatch --no-includes --include-headers --cocci-file test.cocci drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
  File "test.cocci", line 13, column 9, charpos = 219
  around = 'RTA_ALIGN',
  whole content = *     key += RTA_ALIGN(rta->rta_len);
Quoted 4 lines
Quoted 1 line

What can I do to match RTA_ALIGN(...) lines?

I don't understand the problem. I took your rule and your command line, and everything was fine.

I use version:
spatch version 1.0.8-gc1dbb4f-dirty compiled with OCaml version 4.11.1
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

Quoted 8 lines
Quoted 1 line

Maybe parsing error is fixed in new versions?

I can't imagine what would cause a parsing error here. I don't see what could be special about RTA_ALIGN. Normally Coccinelle doesn't even know that it is a macro. Maybe you can try to simplify the semantic patch a little bit and see if there is some change that causes the problem to disappear? Does the problem disappear if you use a name other than RTA_ALIGN?

Changing:

	key += RTA_ALIGN(rta->rta_len);
to:
	key = RTA_ALIGN(rta->rta_len);

makes the parsing error disappear.

Quoted 8 lines

Using aop instead of += leads to the same parsing error:
assignment operator aop;
key aop RTA_ALIGN(rta->rta_len);
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "test.cocci", line 14, column 10, charpos = 245 around = 'RTA_ALIGN',
whole content = * key aop RTA_ALIGN(rta->rta_len);

Quoted 1 line

I assume not, but does spatch --parse-cocci test.cocci work?

Works with "key =" pattern, with "key +=" or "key aop" doesn't. The errors are the same:
spatch --parse-cocci test.cocci
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "test.cocci", line 13, column 9, charpos = 219 around = 'RTA_ALIGN',
whole content = * key += RTA_ALIGN(rta->rta_len);

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