Skip to contentSkip to conversation

smatch update / 2.5.64 / kbugs.org

DISCUSSION dan carpenter 3 participants 3 messages Mar 6, 2003

lore
Share & tools
lore
#0 lore raw

/*
* Smatch is an open source c error checker based
* on the papers about the Stanford Checker.
* (http://smatch.sf.net) The documentation on coding
* smatch checks has been updated since my last email to
* this list.
*
*/

The smatch bugs for kernel 2.5.64 are up. The new url for the smatch bug database is http://kbugs.org.

One new script from Monday was "UnFree." This check looks for variables that aren't freed on the error paths.
http://kbugs.org/cgi-bin/index.py?page=bug_list&script=UnFree&kernel=2.5.64

The bug database is still under heavy construction (ie it is really bad). But I hope to improve it some more this week. Also I plan to add some documentation etc.

The possible bug count for 2.5.64 was 1018. Eventually this information will all be available in a stats page but for now I'll just post the raw SQL...

mysql> select kernelver, script, count(script) from bugs where kernelver = "2.5.64" group by script, kernelver;

+-----------+-------------------+---------------+
| kernelver | script            | count(script) |
+-----------+-------------------+---------------+
| 2.5.64    | Dereference       |           469 |
| 2.5.64    | GFP_DMA           |             7 |
| 2.5.64    | ReleaseRegion     |            14 |
| 2.5.64    | SpinlockUndefined |            44 |
| 2.5.64    | SpinSleepLazy     |             4 |
| 2.5.64    | UncheckedReturn   |           119 |
| 2.5.64    | UnFree            |           333 |
| 2.5.64    | UnreachedCode     |            28 |
+-----------+-------------------+---------------+

8 rows in set (0.07 sec)

regards,
dan carpenter

Signature · 6 lines
_______________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Meet Singles
http://corp.mail.com/lavalife
#1 lore raw
Quoted 11 lines · dan carpenter

/*
* Smatch is an open source c error checker based
* on the papers about the Stanford Checker.
* (http://smatch.sf.net) The documentation on coding
* smatch checks has been updated since my last email to
* this list.
*
*/

The smatch bugs for kernel 2.5.64 are up. The new url for the smatch bug database is http://kbugs.org.

I really appreciate the work you are doing on this project, but I have a comment on how the output is being generated.

What I really need to know is, what are all of the reported errors in a specific portion of the kernel tree. If you give some way to search based on filename and path, I think you will find a lot more people using the results of this tool. I know I would :)

Also, what advantage does signing up for a user account on the kbugs.org site give you?

thanks,

greg k-h

#2 lore raw
In reply to dan carpenter

Hello!

Quoted 2 lines · dan carpenter

The smatch bugs for kernel 2.5.64 are up. The new url for the smatch bug database is http://kbugs.org.

Unfortunatelly the bug database does not work. I mean I cannot connect to it.

Quoted 3 lines

One new script from Monday was "UnFree." This check looks for variables that aren't freed on the error paths.
http://kbugs.org/cgi-bin/index.py?page=bug_list&script=UnFree&kernel=2.5.64

This is very interesting project, thanks a lot.
I spent some time on this today.
This script can produce a lot less false positives with even more custom merge rules. Here's the diff that if run on fs/ext3/super.c from current bk tree, produces
only one true bug. (your version from cvs produces one real bug and two false positives) (8 less hits on my default build).
Still there is a lot room for improvement of course (And probably I will spend some more time on it), there are still valid cases left catched:
pointer assigned to some externally visible variable/structure before exit (fs/reiserfs/fix_node.c) kmalloc only done conditionally (fs/reiserfs/namei.c)
probably more ;)

Also I think with this script it is somewhat easy to catch these cases (well, that needs to be coded of course):
loosing allocated pointer by assigning other value to variable and not storing old value anywhere.

Thank you.

Bye,
Oleg

unfree-new.pl renamed from unfree.pl +33 -2
@@ -12,6 +12,15 @@
     print get_filename(), " ", get_start_line($var), " ", get_lineno(), " ", get_func_pos(), " $msg\n";
 }
 
+
+sub merge_free_and_null($$$){
+    my ($name, $one, $two) = @_;
+
+    if ( ($one eq "free" && $two eq "null") || ($one eq "null" && $two eq "free") ) {
+	return "free";
+    }
+    return merge_rules($name, $one, $two);
+}
 sub merge_rules($$$){
     my ($name, $one, $two) = @_;
 
@@ -36,7 +45,7 @@
 
     return "undefined";
 }
-add_merge_function("merge_rules");
+add_merge_function("merge_free_and_null");
 
 while ($data = get_data()){
     my $tmp;
@@ -88,6 +97,11 @@
 		    set_true_path($name,"non_null");
 		}
 	    }
+	    if ( ! ($cond =~ /_expr/) && ! ($cond =~ /^compound_cond/) ) {
+		if (get_state ($cond)){
+		    set_true_path($cond,"non_null");
+		}
+	    }
 	}
 	for my $cond (@{$conds{falsepath}}){
 	    if ($cond =~ /eq_expr\(\((.*)\)\(integer_cst\(0\)\)\)/){
@@ -102,6 +116,11 @@
 		    set_false_path($name,"null");
 		}
 	    }
+	    if ( ! ($cond =~ /_expr/) && ! ($cond =~ /^compound_cond/) ) {
+		if (get_state ($cond)){
+		    set_false_path($cond,"null");
+		}
+	    }
 	}
     }elsif ($data =~ /^(do_cond) (.*)/){            # check do while() for thouroughness
 	$conds = split_conds($1);
@@ -119,11 +138,23 @@
 		}
 	    }
 	}
+	if ( ! ($cond =~ /_expr/) && ! ($cond =~ /^compound_cond/) ) {
+	    if (get_state ($cond)){
+		set_state($cond,"null");
+	    }
+	}
     }
     
     if ($data =~ /call_expr\(\(addr_expr function_decl\(kfree\)\)\(tree_list: (.*)\)\)/){
 	my $var = $1;
-	if (get_state($var)){
+	my $state = get_state($var);
+	if ( !($state =~ /non_null/) && $state =~ /null/ ) {
+	    error_msg("Freeing null pointer", $state);
+	}
+	if ( $state =~ /free/ ) {
+	    error_msg("Freeing already freed", $state);
+	}
+	if ($state){
 	    set_state($var, "free");
 	}
     }