Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1751332lqb; Sun, 26 May 2024 16:13:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7rEZj6BhbFSJ+kPASA7JO7nrTV4FBo7pgBp+7S2giiEVImm7sRefybc1b6nD/mgshUIjCV+9I9ehnwKUr6w1BONnrPdFxc5OxBKiwoQ== X-Google-Smtp-Source: AGHT+IEUP1aUfWuuM6hBZ26qt9oKjXmk4l/gshQBZYEKhqDjDrUa6z1PZAvoh/CjkM7Wcnhs/Gnr X-Received: by 2002:a17:90a:f2cb:b0:2bf:57a6:1ca0 with SMTP id 98e67ed59e1d1-2bf5f407e99mr6349623a91.40.1716765197306; Sun, 26 May 2024 16:13:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716765197; cv=pass; d=google.com; s=arc-20160816; b=MOjtiRGRmQa7bml6bGYEoSiD+poJ2rd6XPDgEU/6zS7qI8V3oxkp1BSYfgqisfXwUc qLEOhdcpDL1EobOofXGk7jtrjw5ZEIRF0pnzf2QYDljxT16MPBjtRCY05Nne36oI4C0G H48yChBaW/cj4vfurHwc/2MR3UeneHUC+KzXgV3aDE5yRoZOFAKtRPzm4cNO0Ku0rqte 064pVWCr0VnlDG9KDBfCfZJI1BSjz7KBrzfVnVIf3t5uBxE/z6z3t0hQvva58f81mYoW BtaCUNWwhq8/mLd7LjA5JC7P0JEJ0J++zQaCwngYleDrXiiYvGDquWS2IFDZuXMn1V/m HKow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=biIDf2aDdgRErDQlySkeHqUwioy4RCfXpulBaW0oWa8=; fh=DBnAS60VQfCH+VSPVRtyKgvhuaICfy3n2C58oNrYKj4=; b=Qa3apJ1WpklO8pnxFArqm9YztVUdFpObdK7XUEt1vVbUwL7EUll3UMEHLzvAX+VpLX WWZqwSbzFXV5Z2q7Qp+UZxD8Ful8mmnckeAMSaLIEg3WAE8aCSGmz5yQxmfpoxUOlYdg bHdFuRUlYEsdMrHytuF8D0zedhIXbFKSsKD6qdtY8dz6flRp2llnu6p2wDRjtcvQjsEV fs1C51/yWr+y+zbeCp1DIigEYrSy5TSHiYedzppeJlX5TNX3xrrIqM1g5lRQ+hEl3INJ gygiPlE6DxyJ07sFlAi6qHqiVLKH0oYT3I1KjSAiQfNheEUPyWOQbjSu4B2/N4BUXmXz cgFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IaC4aVav; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189895-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bf5fe86b0dsi5124135a91.166.2024.05.26.16.13.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 16:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IaC4aVav; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189895-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 92456281824 for ; Sun, 26 May 2024 23:13:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 883AB13A3E4; Sun, 26 May 2024 23:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IaC4aVav" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3D0B8BE7; Sun, 26 May 2024 23:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716765190; cv=none; b=GkYa1zOKzNceTHbbkqjVvfFQYnp02A2iLZZLa1nhrmdgEdN++6GOxloOJ5dlZwi9IpaY/Pz2C3wXTxsmVX4C+xNqNwwBaEjLH5iPnYXGkvu72KgsS2f5rQHvS+fWzldG+hXmzG9n6SuyoDH3+mBoRqjKsHdp3KuvQrBgaMy5HII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716765190; c=relaxed/simple; bh=5XNbmK1GMH0k0hqdPzWAk8W4SET/yQZHDoHkWs60AHA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=Ih3HwLA0Dh0hqTh1wPAP1+eNMN3kA+FCuihxHxm0uEAfujinScePuZwCYTT7MQKKH9OVXSBgJlmoKVwBcVlBnAGc1Dkh/koZZllFZk5F20o/gks6Ed66daDI1Xtx5Wj8m3m/roiSia2i7foenS+8yGU74oc2AkIrA8IXN9Xx8jM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IaC4aVav; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 511A8C2BD10; Sun, 26 May 2024 23:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716765189; bh=5XNbmK1GMH0k0hqdPzWAk8W4SET/yQZHDoHkWs60AHA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IaC4aVavecDuaPc3f+KW+vB5Zf9a6oNsGMubqfHm292P13hsLogIHU7AVDnJZBgVG yI7wda9yb9c0mji1UZZEtHqibjiekAFCG1bR1LBZlKWTs/Sov+Hy3smPWky8wVDg5X kE2cigOTyYd5tqpmUhVNzGFpSaIgvAfAxkr/9SKYVn+f8ncXIEULTSVaxnmnWsOl95 B6sFMDyDQgMPZ8nTjLVUyLNiEWde6aSKR0O11LfV0hbXoDBt8YVWC0oizzURr4Xd5p h3SmNxJCKT/KmvGkK/sKBnT6fVMedTR3NIjEYYhYkUdCXBnp+LJ/9xzWmCUkwPLtBJ J6aEl4bC3vyPw== Date: Mon, 27 May 2024 08:13:04 +0900 From: Masami Hiramatsu (Google) To: Carlos =?UTF-8?B?TMOzcGV6?= Cc: linux-trace-kernel@vger.kernel.org, Steven Rostedt , Mathieu Desnoyers , Alan Maguire , "open list:TRACING" Subject: Re: [PATCH] tracing/probes: fix error check in parse_btf_field() Message-Id: <20240527081304.8b91f75548838a0781288688@kernel.org> In-Reply-To: References: <20240525182131.15740-1-clopez@suse.de> <20240526191708.860651c915600a535cc2e579@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Sun, 26 May 2024 14:27:56 +0200 Carlos López wrote: > > Hi, > > On 26/5/24 12:17, Masami Hiramatsu (Google) wrote: > > On Sat, 25 May 2024 20:21:32 +0200 > > Carlos López wrote: > > > >> btf_find_struct_member() might return NULL or an error via the > >> ERR_PTR() macro. However, its caller in parse_btf_field() only checks > >> for the NULL condition. Fix this by using IS_ERR() and returning the > >> error up the stack. > >> > > > > Thanks for finding it! > > I think this requires new error message for error_log file. > > Can you add the log as > > > > trace_probe_log_err(ctx->offset, BTF_ERROR); > > > > And define BTF_ERROR in ERRORS@kernel/trace/trace_probe.h ? > > Sounds good, but should we perhaps reuse BAD_BTF_TID? > > ``` > C(BAD_BTF_TID, "Failed to get BTF type info."),\ > ``` > > `btf_find_struct_member()` fails if `type` is not a struct or if it runs > OOM while allocating the anon stack, so it seems appropriate. Good point, it sounds reasonable. Thanks! > > Best, > Carlos > > > Thank you, > > > >> Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access") > >> Signed-off-by: Carlos López > >> --- > >> kernel/trace/trace_probe.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > >> index 5e263c141574..5417e9712157 100644 > >> --- a/kernel/trace/trace_probe.c > >> +++ b/kernel/trace/trace_probe.c > >> @@ -554,6 +554,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type, > >> anon_offs = 0; > >> field = btf_find_struct_member(ctx->btf, type, fieldname, > >> &anon_offs); > >> + if (IS_ERR(field)) > >> + return PTR_ERR(field); > >> if (!field) { > >> trace_probe_log_err(ctx->offset, NO_BTF_FIELD); > >> return -ENOENT; > >> -- > >> 2.35.3 > >> > > > > > > -- > Carlos López > Security Engineer > SUSE Software Solutions -- Masami Hiramatsu (Google)