From: guijianfeng@cn.fujitsu.com (Gui Jianfeng)
Subject: [ltt-dev] [PATCH] lttng: Fix potential invalid pointer derefference
Date: Mon, 23 Feb 2009 14:41:48 +0800 [thread overview]
Message-ID: <49A2452C.9000808@cn.fujitsu.com> (raw)
In-Reply-To: <20090223055955.GA11351@Krystal>
Mathieu Desnoyers wrote:
> * Gui Jianfeng (guijianfeng at cn.fujitsu.com) wrote:
>> Hi Mathieu,
>>
>> Calling get_ltt_root() and put_ltt_root() pair may induce invalid pointer
>> derefference. Consider the following scenario:
>>
>> CPU 0 CPU 1
>> ---------------------- ----------------------
>> 1 root = get_ltt_root()
>> 2 root = get_ltt_root()
>> 3 put_ltt_root() //global root is freed
>> 4 using root(crash here)
>>
>> Here is the fix for this issue. Thanks a lot to Zhaolei to point this out
>> in offline.
>>
>
> Agreed, there is a problem. Please see comments below,
>
>> This patch assumes that the *ltt root remove* patch has been applied.
>>
>> Signed-off-by: Gui Jianfeng <guijianfeng at cn.fujistu.com>
>> ---
>> include/linux/ltt-core.h | 8 +++++++-
>> ltt/ltt-core.c | 38 +++++++++++++++++++++++++++-----------
>
> Only modifications to the two files above seems justified. The rest
> could probably stay as-is.
>
>> ltt/ltt-relay.c | 7 ++++++-
>> ltt/ltt-trace-control.c | 13 +++++++------
>> ltt/ltt-userspace-event.c | 12 ++++++++----
>> 5 files changed, 55 insertions(+), 23 deletions(-)
>>
>> diff --git a/include/linux/ltt-core.h b/include/linux/ltt-core.h
>> index 28394cb..4e20f78 100644
>> --- a/include/linux/ltt-core.h
>> +++ b/include/linux/ltt-core.h
>> @@ -27,11 +27,17 @@ struct ltt_traces {
>>
>> extern struct ltt_traces ltt_traces;
>>
>> +/* ltt's root dir */
>> +struct ltt_root {
>> + atomic_t ref;
>> + struct dentry *root;
>> +};
>> +
>
> Please use include/linux/kref.h.
Do you mean this struct should move into ltt-core.c as following:
struct ltt_root {
struct dentry *root;
struct kref ref;
};
and get_ltt_root() will still return a dentry pointer?
>
>> /*
>> * get dentry of ltt's root dir
>> */
>> +struct ltt_root *get_ltt_root(void);
>> void put_ltt_root(void);
>> -struct dentry *get_ltt_root(void);
>>
> You should not export the "ref". It can be dealt with internally by
> get/put. Creating a struct ltt_root is pointless.
>
>> /* Keep track of trap nesting inside LTT */
>> DECLARE_PER_CPU(unsigned int, ltt_nesting);
>> diff --git a/ltt/ltt-core.c b/ltt/ltt-core.c
>> index 314750b..ed393bd 100644
>> --- a/ltt/ltt-core.c
>> +++ b/ltt/ltt-core.c
>> @@ -6,10 +6,10 @@
>> * Distributed under the GPL license
>> */
>>
>> -#include <linux/ltt-core.h>
>> #include <linux/percpu.h>
>> #include <linux/module.h>
>> #include <linux/debugfs.h>
>> +#include <linux/ltt-core.h>
>>
>
> Don't move headers around.
>
> Thanks,
>
> Mathieu
--
Regards
Gui Jianfeng
next prev parent reply other threads:[~2009-02-23 6:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-23 5:45 Gui Jianfeng
2009-02-23 5:59 ` Mathieu Desnoyers
2009-02-23 6:41 ` Gui Jianfeng [this message]
2009-02-23 6:50 ` Mathieu Desnoyers
2009-02-23 6:55 ` Gui Jianfeng
2009-02-23 9:27 ` [ltt-dev] [PATCH v2] " Gui Jianfeng
2009-02-23 14:37 ` Mathieu Desnoyers
2009-02-24 1:56 ` Gui Jianfeng
2009-02-26 21:36 ` Mathieu Desnoyers
2009-02-27 0:56 ` [ltt-dev] [PATCH v3] " Gui Jianfeng
2009-02-27 2:08 ` Mathieu Desnoyers
2009-02-27 2:11 ` Mathieu Desnoyers
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=49A2452C.9000808@cn.fujitsu.com \
--to=guijianfeng@cn.fujitsu.com \
/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