public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Oleg Drokin <green@linuxhacker.ru>
Cc: smatch@vger.kernel.org
Subject: Re: alloc_page leaks tracing
Date: Thu, 10 Mar 2022 12:42:35 +0300	[thread overview]
Message-ID: <20220310094235.GH3293@kadam> (raw)
In-Reply-To: <1E9B599B-743A-4327-A36A-9DB2AE9E6E51@linuxhacker.ru>

On Tue, Mar 08, 2022 at 12:28:59PM -0500, Oleg Drokin wrote:
> Hello!
> 
>    I am wondering why alloc_page and friends are not considering an allocation function?
>    Found a bit of code where there was an obvious alloc_page leak that was not caught that is caught if I change alloc_page to kmalloc.
> 
>    And while trying to put the support into smatch I suddenly found the structure changed so much from the previous time I looked at it it’s very non-obvious how to add it.
> 
>    I tried adding hooks in check_free_strict.c, check_frees_argument.c, check_leaks.c, smatch_constraints_required.c, smatch_fresh_alloc.c, smatch_parse_call_math.c
>   and tried to insert it alongside kmalloc in smatch_scripts/gen_allocation_list.sh and I still cannot make
>    it work in the actual kernel code even though a modified testcase from validation/sm_memory.c works.
> 
> 
>    Any hint?

The check_leaks.c function is really limitted in the type of leaks it
looks for.  It has basically no false positives, but misses 90% of bugs.

If you're looking for leaks the right place to add it is probably in
check_unwind.c.

regards,
dan carpenter

diff --git a/check_unwind.c b/check_unwind.c
index 569792ad5a57..7ef040d2ca59 100644
--- a/check_unwind.c
+++ b/check_unwind.c
@@ -92,6 +92,10 @@ static struct ref_func_info func_table[] = {
 
 	{ "ieee80211_alloc_hw", ALLOC,  -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },
 	{ "ieee80211_free_hw",  RELEASE, 0, "$" },
+
+	{ "alloc_pages", ALLOC,  -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },
+	{ "__get_free_pages", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },
+	{ "free_pages", RELEASE, 0, "$" },
 };
 
 static struct smatch_state *unmatched_state(struct sm_state *sm)

  reply	other threads:[~2022-03-10  9:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 17:28 alloc_page leaks tracing Oleg Drokin
2022-03-10  9:42 ` Dan Carpenter [this message]
     [not found]   ` <82B7079C-AD17-4E5E-A245-71E9ED53E5A3@linuxhacker.ru>
2022-03-11 21:12     ` Dan Carpenter
2022-03-22  8:05       ` Dan Carpenter
2022-03-25  6:48         ` Dan Carpenter

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=20220310094235.GH3293@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=green@linuxhacker.ru \
    --cc=smatch@vger.kernel.org \
    /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