From patchwork Tue Aug 25 19:21:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 261946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45756C433E1 for ; Tue, 25 Aug 2020 19:22:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27EE02071E for ; Tue, 25 Aug 2020 19:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598383369; bh=wDqYIyNZ05164o+JhG+KyMrtvTksopbr8xCiTsctPKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ok8i2hevbZrOOwrl6TNh7jtfTqA8+8Es5YMTdn7I83TaiQ0EKrfhi+LhKBu7+8/oq AOApRPlZJ41IyKhK/TlZPvNRoFbIy/YvqOg4cCGfyIew7f1cqLlBwZftEgXt2/9wsW z3dJNZ8VEWsdxhNODqn9X8vjUwZuwb+hOa9AYlzA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbgHYTWs convert rfc822-to-8bit (ORCPT ); Tue, 25 Aug 2020 15:22:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42243 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726090AbgHYTWr (ORCPT ); Tue, 25 Aug 2020 15:22:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-hTnt2NlbM3W9WwC6odc6Hg-1; Tue, 25 Aug 2020 15:21:37 -0400 X-MC-Unique: hTnt2NlbM3W9WwC6odc6Hg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9CE281CAF9; Tue, 25 Aug 2020 19:21:35 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4319619C4F; Tue, 25 Aug 2020 19:21:33 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer Subject: [PATCH v12 bpf-next 01/14] tools resolve_btfids: Add size check to get_id function Date: Tue, 25 Aug 2020 21:21:11 +0200 Message-Id: <20200825192124.710397-2-jolsa@kernel.org> In-Reply-To: <20200825192124.710397-1-jolsa@kernel.org> References: <20200825192124.710397-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To make sure we don't crash on malformed symbols. Acked-by: Andrii Nakryiko Signed-off-by: Jiri Olsa --- tools/bpf/resolve_btfids/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index 4d9ecb975862..35a172d3d80d 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -199,9 +199,16 @@ static char *get_id(const char *prefix_end) /* * __BTF_ID__func__vfs_truncate__0 * prefix_end = ^ + * pos = ^ */ - char *p, *id = strdup(prefix_end + sizeof("__") - 1); + int len = strlen(prefix_end); + int pos = sizeof("__") - 1; + char *p, *id; + if (pos >= len) + return NULL; + + id = strdup(prefix_end + pos); if (id) { /* * __BTF_ID__func__vfs_truncate__0