Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2018377pxb; Fri, 24 Sep 2021 18:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOfp5ic7FN0v8iEAbhzxH5sWVLbPin1fsyoQ5bX/4DZbBcM+Mwhs89ix5B7lYaMQhoEq1C X-Received: by 2002:a05:6402:2050:: with SMTP id bc16mr8524193edb.270.1632532029304; Fri, 24 Sep 2021 18:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632532029; cv=none; d=google.com; s=arc-20160816; b=oxtnnXo5tppHaGzpJjQFc46ANzuqY9waTiO8kg7NAgYRpEzQ/F1aPhBxWzpXpgTaTV 0JDNRHZTp393jBUz54CJPhcKHz7Sv+77hx+2G2NoiZe/NvRcZU69E6hZcs6WE0iNSUK8 gZtQKjjlN0GhKIRSj+mx6db+wCMdP9A3WfFJfQr3SrMLekFaH5IVKTHaNKUT4vHmCKtq NHufCGzC2tsWZfzka9xZdSb6s7fn1zjss/F6A7PhJIq/kyWsVnYWG8nn4bJtcs3D2x5I bNnnwF6AwjxSMDMVSxzHJWdImnyu9sgKS91a043Fz8hJMmWhZo2mdhi3Y95TMz6M38G4 1RJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eJczbxCTLgMN762FoZK7X7EA0STDgnqYogdOaHtE9u8=; b=OYRb+9/BmHEZyRIDPO6SFlVj4rP/a50Ze+BDpak7pChn3DpSfkKC/iRXAaepFK3+da ASsK8edgNZDiUAr4/MHCb12V55tm0cA4K73Yfdd0j3lGNUYYwfVUdmifIBLQyOz85HM4 rw+gAu9kb38ZqD7i/EcuKIOVZppFbi5mV2MAW+2Y7zOUFZgvg8Em91X2lBbnA6UiciS7 qqO5DcWjV0ScfxyrWZOhMmNquYlV55Wd0g78nJ7Lcmo9KgSYY6js37fsihk/JJafEtLX cnQYMrvOke/TJ2ynSRzkDOqn1/zTj2TtNt9OHZHnlpHovIUVtyPltJa4E/DCdhVeLoLJ zT5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QhlCin+y; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v23si1586145eda.182.2021.09.24.18.06.46; Fri, 24 Sep 2021 18:07:09 -0700 (PDT) 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=@google.com header.s=20210112 header.b=QhlCin+y; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346962AbhIXPWW (ORCPT + 99 others); Fri, 24 Sep 2021 11:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346995AbhIXPWV (ORCPT ); Fri, 24 Sep 2021 11:22:21 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB3D5C061571 for ; Fri, 24 Sep 2021 08:20:47 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id s16so6475127ybe.0 for ; Fri, 24 Sep 2021 08:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eJczbxCTLgMN762FoZK7X7EA0STDgnqYogdOaHtE9u8=; b=QhlCin+yArkYZSWzZFKZqB8RGHyWfqjFekguOJfvRv/YwbcIGWM+4VAedrIQUheoFM sMvZYJldiRa0+JN7esyHyy191nNcor49uWafVWFXV/B1jhSzwKUR9fKq/qcrqTpIbhXO 3zzHuMk4xz+JdibriRjhnZBmJx2r1PMaJfC/xsfDliXCgGirAH0l9FuF8kSWj8SG4u6n PDQnuddYbriIP4CAj7I2jPTaHL00nj6Mumwa2Ogqxgq4Zd74uTGqR4+B8JP1dKnY0mz+ 1MSiCbGwycjDZ2W4vcV8Enhf7G60h2caNrRtgh637c3H4tjy7KPIUD5RzYCG8Ml6u7rv Xlww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eJczbxCTLgMN762FoZK7X7EA0STDgnqYogdOaHtE9u8=; b=JI4ZTd2mPO5UmtEl+r5tOaA4qwXgPChQzb8iX65xXkwZx+4v56VMrooZ1oCFUKQdx2 3lIkuqnskvrPBj6ok3LnMlcC664Jxkz4P9r0F/7hoASOaOn8G+hmWOgui7m/zXIuZoQ6 pDHdg4A0krb9dSUKyi2gAFUC3dn/2vLmTynLlfkKmWhJ6VJ224LKHWAoIvdVw92jZ0Oa y9PmZ/7P/LHfnsV7LbM5xPPMFugeFvI1tOWdEZwOpvvb1HWMVOof/Rgmfp8T0aObepTV cRVIK9l4N44yqz2vsvupII4t10xuLIcpuQ3HNIZS23n1PqUhoiR8SeijTGgT4FQ0ReCm BgjQ== X-Gm-Message-State: AOAM530GMUVxQk4p3RhOQ/kYL/xck0Y6laAKcjwWWwSAawgwdW36gbJ2 Z9diNzD5E88VU/kQafiRiN29ERUMd9gNcRnZlnDNYA== X-Received: by 2002:a25:d2ce:: with SMTP id j197mr14249240ybg.160.1632496846776; Fri, 24 Sep 2021 08:20:46 -0700 (PDT) MIME-Version: 1.0 References: <20210923170908.2184404-1-kaleshsingh@google.com> In-Reply-To: <20210923170908.2184404-1-kaleshsingh@google.com> From: Sami Tolvanen Date: Fri, 24 Sep 2021 08:20:35 -0700 Message-ID: Subject: Re: [PATCH] tracing/cfi: Fix cmp_entries_* functions signature mismatch To: Kalesh Singh Cc: surenb@google.com, Hridya Valsaraju , namhyung@kernel.org, Nick Desaulniers , Android Kernel Team , Steven Rostedt , Ingo Molnar , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kalesh, On Thu, Sep 23, 2021 at 10:09 AM Kalesh Singh wrote: > > If CONFIG_CFI_CLANG=y, attempting to read an event histogram will cause > the kernel to panic due to failed CFI check. > > 1. echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger > 2. cat >> events/sched/sched_switch/hist > 3. kernel panices on attempting to read hist > > This happens because the sort() function expects a generic > int (*)(const void *, const void *) pointer for the compare function. > To prevent this CFI failure, change tracing map cmp_entries_* function > signatures to match this. > > Signed-off-by: Kalesh Singh > --- > kernel/trace/tracing_map.c | 40 ++++++++++++++++++++++---------------- > 1 file changed, 23 insertions(+), 17 deletions(-) > > diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c > index d6bddb157ef2..a8c80ebbf9da 100644 > --- a/kernel/trace/tracing_map.c > +++ b/kernel/trace/tracing_map.c > @@ -834,19 +834,21 @@ int tracing_map_init(struct tracing_map *map) > return err; > } > > -static int cmp_entries_dup(const struct tracing_map_sort_entry **a, > - const struct tracing_map_sort_entry **b) > +static int cmp_entries_dup(const void *__a, const void *__b) > { > int ret = 0; > + const struct tracing_map_sort_entry *a > + = *(const struct tracing_map_sort_entry **)__a; > + const struct tracing_map_sort_entry *b > + = *(const struct tracing_map_sort_entry **)__b; > > - if (memcmp((*a)->key, (*b)->key, (*a)->elt->map->key_size)) > + if (memcmp(a->key, b->key, a->elt->map->key_size)) > ret = 1; > > return ret; > } > > -static int cmp_entries_sum(const struct tracing_map_sort_entry **a, > - const struct tracing_map_sort_entry **b) > +static int cmp_entries_sum(const void *__a, const void *__b) > { > const struct tracing_map_elt *elt_a, *elt_b; > struct tracing_map_sort_key *sort_key; > @@ -854,9 +856,13 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a, > tracing_map_cmp_fn_t cmp_fn; > void *val_a, *val_b; > int ret = 0; > + const struct tracing_map_sort_entry *a > + = *(const struct tracing_map_sort_entry **)__a; > + const struct tracing_map_sort_entry *b > + = *(const struct tracing_map_sort_entry **)__b; > > - elt_a = (*a)->elt; > - elt_b = (*b)->elt; > + elt_a = a->elt; > + elt_b = b->elt; > > sort_key = &elt_a->map->sort_key; > > @@ -873,8 +879,7 @@ static int cmp_entries_sum(const struct tracing_map_sort_entry **a, > return ret; > } > > -static int cmp_entries_key(const struct tracing_map_sort_entry **a, > - const struct tracing_map_sort_entry **b) > +static int cmp_entries_key(const void *__a, const void *__b) > { > const struct tracing_map_elt *elt_a, *elt_b; > struct tracing_map_sort_key *sort_key; > @@ -882,9 +887,13 @@ static int cmp_entries_key(const struct tracing_map_sort_entry **a, > tracing_map_cmp_fn_t cmp_fn; > void *val_a, *val_b; > int ret = 0; > + const struct tracing_map_sort_entry *a > + = *(const struct tracing_map_sort_entry **)__a; > + const struct tracing_map_sort_entry *b > + = *(const struct tracing_map_sort_entry **)__b; > > - elt_a = (*a)->elt; > - elt_b = (*b)->elt; > + elt_a = a->elt; > + elt_b = b->elt; > > sort_key = &elt_a->map->sort_key; > > @@ -989,10 +998,8 @@ static void sort_secondary(struct tracing_map *map, > struct tracing_map_sort_key *primary_key, > struct tracing_map_sort_key *secondary_key) > { > - int (*primary_fn)(const struct tracing_map_sort_entry **, > - const struct tracing_map_sort_entry **); > - int (*secondary_fn)(const struct tracing_map_sort_entry **, > - const struct tracing_map_sort_entry **); > + int (*primary_fn)(const void *, const void *); > + int (*secondary_fn)(const void *, const void *); > unsigned i, start = 0, n_sub = 1; > > if (is_key(map, primary_key->field_idx)) > @@ -1061,8 +1068,7 @@ int tracing_map_sort_entries(struct tracing_map *map, > unsigned int n_sort_keys, > struct tracing_map_sort_entry ***sort_entries) > { > - int (*cmp_entries_fn)(const struct tracing_map_sort_entry **, > - const struct tracing_map_sort_entry **); > + int (*cmp_entries_fn)(const void *, const void *); > struct tracing_map_sort_entry *sort_entry, **entries; > int i, n_entries, ret; > > Thanks for the patch! This looks correct to me and fixes the function type mismatch that trips CFI. Reviewed-by: Sami Tolvanen Sami