From: Song Liu <liu.song.a23@gmail.com>
To: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Oleg Nesterov <oleg@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
mhiramat@kernel.org, Peter Zijlstra <peterz@infradead.org>,
mingo@redhat.com, acme@kernel.org,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, open list <linux-kernel@vger.kernel.org>,
ananth@linux.vnet.ibm.com,
Alexis Berlemont <alexis.berlemont@gmail.com>,
naveen.n.rao@linux.vnet.ibm.com,
linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org,
linux@armlinux.org.uk, ralf@linux-mips.org, paul.burton@mips.com
Subject: Re: [PATCH v8 3/6] Uprobes: Support SDT markers having reference count (semaphore)
Date: Mon, 13 Aug 2018 09:50:32 -0700 [thread overview]
Message-ID: <CAPhsuW5K8+m23qRR3hDxTa1nwZ+1hHH0Mu-2EmjP1-rOjQ03_g@mail.gmail.com> (raw)
In-Reply-To: <95a1221e-aecc-42be-5239-a2c2429be176@linux.ibm.com>
On Sun, Aug 12, 2018 at 10:47 PM, Ravi Bangoria
<ravi.bangoria@linux.ibm.com> wrote:
> Hi Song,
>
> On 08/11/2018 01:27 PM, Song Liu wrote:
>>> +
>>> +static void delayed_uprobe_delete(struct delayed_uprobe *du)
>>> +{
>>> + if (!du)
>>> + return;
>> Do we really need this check?
>
>
> Not necessary though, but I would still like to keep it for a safety.
>
>
>>
>>> + list_del(&du->list);
>>> + kfree(du);
>>> +}
>>> +
>>> +static void delayed_uprobe_remove(struct uprobe *uprobe, struct mm_struct *mm)
>>> +{
>>> + struct list_head *pos, *q;
>>> + struct delayed_uprobe *du;
>>> +
>>> + if (!uprobe && !mm)
>>> + return;
>> And do we really need this check?
>
>
> Yes. delayed_uprobe_remove(uprobe=NULL, mm=NULL) is an invalid case. If I remove
> this check, code below (or more accurately code suggested by Oleg) will remove
> all entries from delayed_uprobe_list. So I will keep this check but put a comment
> above function.
>
>
> [...]
>>> +
>>> + ret = get_user_pages_remote(NULL, mm, vaddr, 1,
>>> + FOLL_WRITE, &page, &vma, NULL);
>>> + if (unlikely(ret <= 0)) {
>>> + /*
>>> + * We are asking for 1 page. If get_user_pages_remote() fails,
>>> + * it may return 0, in that case we have to return error.
>>> + */
>>> + ret = (ret == 0) ? -EBUSY : ret;
>>> + pr_warn("Failed to %s ref_ctr. (%d)\n",
>>> + d > 0 ? "increment" : "decrement", ret);
>> This warning is not really useful. Seems this function has little information
>> about which uprobe is failing here. Maybe we only need warning in the caller
>> (or caller of caller).
>
>
> Sure, I can move this warning to caller of this function but what are the
> exact fields you would like to print with warning? Something like this is
> fine?
>
> pr_warn("ref_ctr %s failed for 0x%lx, 0x%lx, 0x%lx, 0x%p",
> d > 0 ? "increment" : "decrement", inode->i_ino,
> offset, ref_ctr_offset, mm);
>
> More importantly, the reason I didn't print more info is because dmesg is
> accessible to unprivileged users in many distros but uprobes are not. So
> printing this information may be a security violation. No?
>
>
>>
>>> + return ret;
>>> + }
>>> +
>>> + kaddr = kmap_atomic(page);
>>> + ptr = kaddr + (vaddr & ~PAGE_MASK);
>>> +
>>> + if (unlikely(*ptr + d < 0)) {
>>> + pr_warn("ref_ctr going negative. vaddr: 0x%lx, "
>>> + "curr val: %d, delta: %d\n", vaddr, *ptr, d);
>>> + ret = -EINVAL;
>>> + goto out;
>>> + }
>>> +
>>> + *ptr += d;
>>> + ret = 0;
>>> +out:
>>> + kunmap_atomic(kaddr);
>>> + put_page(page);
>>> + return ret;
>>> +}
>>> +
>>> +static int update_ref_ctr(struct uprobe *uprobe, struct mm_struct *mm,
>>> + bool is_register)
>> What's the reason of bool is_register here vs. short d in __update_ref_ctr()?
>> Can we use short for both?
>
>
> Yes, I can use short as well.
>
>
>>
>>> +{
>>> + struct vm_area_struct *rc_vma;
>>> + unsigned long rc_vaddr;
>>> + int ret = 0;
>>> +
>>> + rc_vma = find_ref_ctr_vma(uprobe, mm);
>>> +
>>> + if (rc_vma) {
>>> + rc_vaddr = offset_to_vaddr(rc_vma, uprobe->ref_ctr_offset);
>>> + ret = __update_ref_ctr(mm, rc_vaddr, is_register ? 1 : -1);
>>> +
>>> + if (is_register)
>>> + return ret;
>>> + }
>> Mixing __update_ref_ctr() here and delayed_uprobe_add() in the same
>> function is a little confusing (at least for me). How about we always use
>> delayed uprobe for uprobe_mmap() and use non-delayed in other case(s)?
>
>
> No. delayed_uprobe_add() is needed for uprobe_register() case to handle race
> between uprobe_register() and process creation.
I see.
>
>
> [...]
>>>
>>> +static int delayed_uprobe_install(struct vm_area_struct *vma)
>> This function name is confusing. How about we call it delayed_ref_ctr_incr() or
>> something similar? Also, we should add comments to highlight this is vma is not
>> the vma containing the uprobe, but the vma containing the ref_ctr.
>
>
> Sure, I'll do that.
>
>
>>
>>> +{
>>> + struct list_head *pos, *q;
>>> + struct delayed_uprobe *du;
>>> + unsigned long vaddr;
>>> + int ret = 0, err = 0;
>>> +
>>> + mutex_lock(&delayed_uprobe_lock);
>>> + list_for_each_safe(pos, q, &delayed_uprobe_list) {
>>> + du = list_entry(pos, struct delayed_uprobe, list);
>>> +
>>> + if (!valid_ref_ctr_vma(du->uprobe, vma))
>>> + continue;
>>> +
>>> + vaddr = offset_to_vaddr(vma, du->uprobe->ref_ctr_offset);
>>> + ret = __update_ref_ctr(vma->vm_mm, vaddr, 1);
>>> + /* Record an error and continue. */
>>> + if (ret && !err)
>>> + err = ret;
>> I think this is a good place (when ret != 0) to call pr_warn(). I guess we can
>> print which mm get error for which uprobe (inode+offset).
>
>
> __update_ref_ctr() is already printing warning, so I didn't add anything here.
> In case I remove a warning from __update_ref_ctr(), a warning something like
> below is fine?
>
> pr_warn("ref_ctr increment failed for 0x%lx, 0x%lx, 0x%lx, 0x%p",
> inode->i_ino, offset, ref_ctr_offset, vma->vm_mm);
>
I was thinking about a message like:
ref_ctr increment failed for inode XX offset YY ref_ctr ZZ of mm 0xWWW
I didn't thought about the security part of it, but I guess it is OK.
Thanks,
Song
> Again, can this lead to a security violation?
>
> Thanks for detailed review :)
> -Ravi
>
next prev parent reply other threads:[~2018-08-13 16:50 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-09 4:18 [PATCH v8 0/6] Uprobes: Support SDT markers having reference count (semaphore) Ravi Bangoria
2018-08-09 4:18 ` [PATCH v8 1/6] Uprobes: Simplify uprobe_register() body Ravi Bangoria
2018-08-11 8:00 ` Song Liu
2018-08-13 8:56 ` Srikar Dronamraju
2018-08-14 0:07 ` Steven Rostedt
2018-08-09 4:18 ` [PATCH v8 2/6] Uprobe: Additional argument arch_uprobe to uprobe_write_opcode() Ravi Bangoria
2018-08-11 8:01 ` Song Liu
2018-08-13 8:51 ` Srikar Dronamraju
2018-08-09 4:18 ` [PATCH v8 3/6] Uprobes: Support SDT markers having reference count (semaphore) Ravi Bangoria
2018-08-09 14:38 ` Oleg Nesterov
2018-08-10 19:58 ` Steven Rostedt
2018-08-11 6:14 ` Song Liu
2018-08-14 0:01 ` Steven Rostedt
2018-08-14 0:05 ` Steven Rostedt
2018-08-11 7:57 ` Song Liu
2018-08-11 15:37 ` Steven Rostedt
2018-08-13 5:47 ` Ravi Bangoria
2018-08-13 7:38 ` Ravi Bangoria
2018-08-13 11:50 ` Oleg Nesterov
2018-08-13 13:01 ` Ravi Bangoria
2018-08-13 13:17 ` Oleg Nesterov
2018-08-13 14:26 ` Ravi Bangoria
2018-08-13 14:51 ` Oleg Nesterov
2018-08-13 17:12 ` Song Liu
2018-08-14 4:37 ` Ravi Bangoria
2018-08-14 16:35 ` Song Liu
2018-08-14 0:03 ` Steven Rostedt
2018-08-13 16:50 ` Song Liu [this message]
2018-08-13 10:03 ` Srikar Dronamraju
2018-08-13 11:23 ` Oleg Nesterov
2018-08-14 8:56 ` Ravi Bangoria
2018-08-09 4:18 ` [PATCH v8 4/6] Uprobes/sdt: Prevent multiple reference counter for same uprobe Ravi Bangoria
2018-08-11 8:04 ` Song Liu
2018-08-13 8:50 ` Srikar Dronamraju
2018-08-09 4:18 ` [PATCH v8 5/6] trace_uprobe/sdt: " Ravi Bangoria
2018-08-11 8:12 ` Song Liu
2018-08-13 8:19 ` Ravi Bangoria
2018-08-13 8:49 ` Srikar Dronamraju
2018-08-13 16:27 ` Song Liu
2018-08-13 8:48 ` Srikar Dronamraju
2018-08-09 4:18 ` [PATCH v8 6/6] perf probe: Support SDT markers having reference counter (semaphore) Ravi Bangoria
2018-08-13 16:55 ` [PATCH v8 0/6] Uprobes: Support SDT markers having reference count (semaphore) Oleg Nesterov
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=CAPhsuW5K8+m23qRR3hDxTa1nwZ+1hHH0Mu-2EmjP1-rOjQ03_g@mail.gmail.com \
--to=liu.song.a23@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexis.berlemont@gmail.com \
--cc=ananth@linux.vnet.ibm.com \
--cc=jolsa@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux@armlinux.org.uk \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=oleg@redhat.com \
--cc=paul.burton@mips.com \
--cc=peterz@infradead.org \
--cc=ralf@linux-mips.org \
--cc=ravi.bangoria@linux.ibm.com \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).