Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4347693pxb; Tue, 2 Mar 2021 12:46:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx1ItsXERJfzH6PENhyePh5A3LTBB8FjYhutTArfi7qWLtsULN4RcTFnSe+JD8RcD+ZlT7 X-Received: by 2002:aa7:c84b:: with SMTP id g11mr22127383edt.169.1614717986250; Tue, 02 Mar 2021 12:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614717986; cv=none; d=google.com; s=arc-20160816; b=p90WmDGxxc9kUp2QZqAFEssG6/F7/2BDYb0JieqtQyTs0/hIain/xsLU5Bx+O/T6EN PgcxsyFfNYQQaSqbW3YSzAZcwSE4xTWY6AhXDEmALSyvFk4Qb5td7xUvKOFjTN8FkzVc uPAhje8ACY6LTZAWgZaVMeD5YAUGM3nWRnLnFwmXnNuTAqv8cAoeWEpVlyhfNniFLK8k Lian2ee8QyfddVIHDHKFs+CR2a2GXXSPiiSxsVZ1bk/+/tyYnTvCDiwWbMbBj+GtLVBW 5I3Or0uozSoYvDC+ei/JPo9IZ7jcThiQSUe/haEayXEWfD4SnABB1HKn4h6UAV2lc0jD nWjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=t2ZiZvOsWXyRohVFi8sr69QFf++HwrlNW9DX12B0w68=; b=1A2qyZFSoy/R3ZbbegavnQ9YRhlBsd1gjal/7kc74y8sQ534W1YW4FizbOXusXLHJS C5qNeqPrVerOv2v4ADXlOF3eOaJJg+SsgDWxiGYUU8Kn5T214zIl0tc32MFgk8a0kTHS yA8P5uujc0cn4QQsEhbduHtu3eMoeoiJDuH7tEn6Yjq6fMmyT3wKmESBGEPhKToMJC3R iniaEcMeAHqRJjh7xSeN0pR5qP6Al6SJ7uCNtFslyhH1k2n2bPmAqF0I4EdFIumMOMK2 W+QHuNhJBIfm6zE9FfF4bjIwR/cqlioP7LY4/GZrHMB3iVupRBpSZDJzMChUOcb6WLvp hpqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qYL67jtv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx25si3814624edb.242.2021.03.02.12.46.01; Tue, 02 Mar 2021 12:46:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qYL67jtv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377919AbhCBIox (ORCPT + 99 others); Tue, 2 Mar 2021 03:44:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:50252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349458AbhCBIZU (ORCPT ); Tue, 2 Mar 2021 03:25:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E01326148E; Tue, 2 Mar 2021 08:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614673441; bh=CpzI4Qq3HpAUm+Ff4gmctdpIRhmEXGG9TE6ucokTozY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qYL67jtv2Q77JAOc80jZRkCXt1bfXU0wzM8OLiKhzyPd8un1t1a6G8aEs4tSzw5qG 8yH6NQoWIUi7R1FC1LTn+nmsJd0bPXWAFKej1MDxtf8YY3AJWZf2d8mCLqcDKBm8sG 3ru9kMH8gSZHSNNSwNhQB5u47MARpQm0ql5A2EUELSMJyIXSj6+QQXXpfQaOPmhR9l 7Fbvn41n9w4MBw07B/74PTimC/tZxnL7FlqAVr5XSo9GUymkhnj7YJ8o3cVjZnIWY+ gE7bNRb09QH382MlgBTu9lG7JgrIUOSRLlJCytW/Ft8OQJ6iwoiySWzkrEIx0MZnI+ qyEqqHyMoyYlA== Date: Tue, 2 Mar 2021 16:23:55 +0800 From: Peter Chen To: Pawel Laszczak , Steven Rostedt Cc: Linus Torvalds , Linux Kernel Mailing List , Ingo Molnar , Andrew Morton , Masami Hiramatsu , Jacob Wen , Felipe Balbi , Greg KH Subject: Re: [PATCH 0/2] tracing: Detect unsafe dereferencing of pointers from trace events Message-ID: <20210302082355.GA8633@nchen> References: <20210226185909.100032746@goodmis.org> <20210227141802.5c9aca91@oasis.local.home> <20210227190831.56956c80@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-03-01 05:27:04, Pawel Laszczak wrote: > > + Peter Chen - Maintainer of CDNS3 driver > > > > >[ Resending with an address that should work for Felipe ] > > > >On Sat, 27 Feb 2021 14:18:02 -0500 > >Steven Rostedt wrote: > > > >> On Fri, 26 Feb 2021 14:21:00 -0800 > >> Linus Torvalds wrote: > >> > >> > On Fri, Feb 26, 2021 at 11:07 AM Steven Rostedt wrote: > >> > > > >> > > The first patch scans the print fmts of the trace events looking for > >> > > dereferencing pointers from %p*, and making sure that they refer back > >> > > to the trace event itself. > >> > > > >> > > The second patch handles strings "%s" [..] > >> > > >> > Doing this at runtime really feels like the wrong thing to do. > >> > > >> > It won't even protect us from what happened - people like me and > >> > Andrew won't even run those tracepoints in the first place, so we > >> > won't notice. > >> > > >> > It really would be much better in every respect to have this done by > >> > checkpatch, I think. > >> > >> And after fixing the parsing to not trigger false positives, an > >> allyesconfig boot found this: > >> > >> event cdns3_gadget_giveback has unsafe dereference of argument 11 > >> print_fmt: "%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d, trb: [start:%d, end:%d: virt addr %pa], flags:%x SID: %u", > >__get_str(name), REC->req, REC->buf, > >> REC->actual, REC->length, REC->zero ? "Z" : "z", REC->short_not_ok ? "S" : "s", REC->no_interrupt ? "I" : "i", REC->status, REC- > >>start_trb, REC->end_trb, REC->start_trb_addr, REC->flags, RE > >> C->stream_id > >> > >> (as the above is from a trace event class, it triggered for every event > >> in that class). > >> > >> As it looks like it uses %pa which IIUC from the printk code, it > >> dereferences the pointer to find it's virtual address. The event has > >> this as the field: > >> > >> __field(struct cdns3_trb *, start_trb_addr) > >> > >> Assigns it with: > >> > >> __entry->start_trb_addr = req->trb; > >> > >> And prints that with %pa, which will dereference pointer at the time of > >> reading, where the address in question may no longer be around. That > >> looks to me as a potential bug. Steven, thanks for reporting. Do you mind sending patch to fix it? If you have no time to do it, I will do it later. -- Thanks, Peter Chen