linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts/coccinelle: catch freeing cryptographic structures via kfree
@ 2014-11-17 14:14 Konstantin Khlebnikov
  2014-11-17 14:14 ` [PATCH 2/2] kernel/kexec: free crypto_shash using crypto_free_shash Konstantin Khlebnikov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Konstantin Khlebnikov @ 2014-11-17 14:14 UTC (permalink / raw)
  To: kexec, linux-kernel, Eric Biederman
  Cc: Michal Marek, Herbert Xu, Gilles Muller, Nicolas Palix,
	Julia Lawall, linux-crypto, David S. Miller

Structures allocated by crypto_alloc_* must be freed using crypto_free_*.

Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
---
 scripts/coccinelle/free/crypto_free.cocci |   45 +++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 scripts/coccinelle/free/crypto_free.cocci

diff --git a/scripts/coccinelle/free/crypto_free.cocci b/scripts/coccinelle/free/crypto_free.cocci
new file mode 100644
index 0000000..0799b70
--- /dev/null
+++ b/scripts/coccinelle/free/crypto_free.cocci
@@ -0,0 +1,45 @@
+///
+/// Structures allocated by crypto_alloc_* must be freed using crypto_free_*.
+/// This finds freeing them by kfree.
+///
+// Confidence: Moderate
+// Copyright: (C) 2014 Konstantin Khlebnikov,  GPLv2.
+// Comments: There are false positives in crypto/ where they are actually freed.
+// Keywords: crypto, kfree
+// Options: --no-includes --include-headers
+
+virtual org
+virtual report
+virtual context
+
+@r depends on context || org || report@
+expression x;
+identifier crypto_alloc =~ "^crypto_alloc_";
+@@
+
+(
+ x = crypto_alloc(...)
+)
+
+@pb@
+expression r.x;
+position p;
+@@
+
+(
+* kfree@p(x)
+)
+
+@script:python depends on org@
+p << pb.p;
+@@
+
+msg="WARNING: invalid free of crypto_alloc_* allocated data"
+coccilib.org.print_todo(p[0], msg)
+
+@script:python depends on report@
+p << pb.p;
+@@
+
+msg="WARNING: invalid free of crypto_alloc_* allocated data"
+coccilib.report.print_report(p[0], msg)


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-11-23 16:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 14:14 [PATCH 1/2] scripts/coccinelle: catch freeing cryptographic structures via kfree Konstantin Khlebnikov
2014-11-17 14:14 ` [PATCH 2/2] kernel/kexec: free crypto_shash using crypto_free_shash Konstantin Khlebnikov
2014-11-17 15:30 ` [PATCH 1/2] scripts/coccinelle: catch freeing cryptographic structures via kfree Julia Lawall
2014-11-17 15:40   ` Konstantin Khlebnikov
2014-11-18 10:50 ` [PATCH 1/2 v2] " Konstantin Khlebnikov
2014-11-19  9:41   ` Julia Lawall
2014-11-19 15:06     ` Konstantin Khlebnikov
2014-11-23 16:45       ` Julia Lawall

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).