Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp272443pxb; Thu, 14 Jan 2021 05:44:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUqeBSjz2Xo8Uhg75+L4kMLcbhcTslMSmy+mXWpuSJDt76CGoD2ELFh7D/b4zln7zpLl6G X-Received: by 2002:a05:6402:404:: with SMTP id q4mr5888732edv.295.1610631853084; Thu, 14 Jan 2021 05:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610631853; cv=none; d=google.com; s=arc-20160816; b=p+rJpA4RPN60LwT0sE/+vnzYnLhxSDLgQBnYJbfFuEIiEZp063v746A3hFYt05UhH2 ALN2bfS0/rJvYalv2h+2SUT0qHjCHeltbfvExkWzL+ostR44r/by+ZZ7qLyl/Pu2spts rccOr4JpRvB+e6v07ZuWRwS5Oz9pKGEOHv1ZblW4rP89mbzfJk127+bzkRzLoMC1HuPY SN5ap7DoPe9O+sBbKJo3bra0gqPzgwXJ2fAzNAC75bW6e4lTlIBsM2MrF8c4kTamZZB3 MpQuOg0ncVBhQHhqLV/rmw5fzq+JbPFp4TWiGbLi+iGHqjP60jJmze3OQExY7nc4+Gpg sglA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ElW4bEPPQ3I7DnMuZtUkQzE7eKb26iPbAJSH3gzg0sk=; b=e4unhbp/tqSQ7FrCFtQcwbR0IZvjwWNYP5ieQqPuBPpLJUdO4bcuxr/LguyQpAEYdl c+Y7Kx6XASKpdQ07PQrgY+vdkFzDFF2vHudUbakAuqK4oFyqU3U0kmoO6PO+XhNCfeC3 fQLeLZXHw2PQkgs7BnixEq/Q0wS2CH3eldpTUNP2bKg9H6kwTjcyNaR1vA0fr5dy5rMv MJnCpAP6eNp5aBqWKop39tuyjoE7g1J2d1RAPloKEQ7PW7KbUVZcKMfssgcuQIMBn0SW C7VD9a8OS7/86UwmP3zzuM6hwwtvg6tx9MfZsYlKer7GMe582kfDGI6l1hYYfyGbvdOR kUeg== ARC-Authentication-Results: i=1; mx.google.com; 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 m1si2346475eja.95.2021.01.14.05.43.49; Thu, 14 Jan 2021 05:44:13 -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; 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 S1728952AbhANNmD convert rfc822-to-8bit (ORCPT + 99 others); Thu, 14 Jan 2021 08:42:03 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:50945 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728824AbhANNmD (ORCPT ); Thu, 14 Jan 2021 08:42:03 -0500 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-317-ntUoY5jkMQeCGFSfPfxLhQ-1; Thu, 14 Jan 2021 08:41:05 -0500 X-MC-Unique: ntUoY5jkMQeCGFSfPfxLhQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B39FB190A7A7; Thu, 14 Jan 2021 13:41:02 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.195.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id B587C60C47; Thu, 14 Jan 2021 13:40:55 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov , Song Liu , lkml , bpf@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH bpf-next 2/3] bpf: Add size arg to build_id_parse function Date: Thu, 14 Jan 2021 14:40:43 +0100 Message-Id: <20210114134044.1418404-3-jolsa@kernel.org> In-Reply-To: <20210114134044.1418404-1-jolsa@kernel.org> References: <20210114134044.1418404-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible to have other build id types (other than default SHA1). Currently there's also ld support for MD5 build id. Adding size argument to build_id_parse function, that returns (if defined) size of the parsed build id, so we can recognize the build id type. Cc: Alexei Starovoitov Cc: Song Liu Signed-off-by: Jiri Olsa --- include/linux/buildid.h | 3 ++- kernel/bpf/stackmap.c | 2 +- lib/buildid.c | 29 +++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/linux/buildid.h b/include/linux/buildid.h index 08028a212589..40232f90db6e 100644 --- a/include/linux/buildid.h +++ b/include/linux/buildid.h @@ -6,6 +6,7 @@ #define BUILD_ID_SIZE_MAX 20 -int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id); +int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, + __u32 *size); #endif diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 55d254a59f07..cabaf7db8efc 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -189,7 +189,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, for (i = 0; i < trace_nr; i++) { vma = find_vma(current->mm, ips[i]); - if (!vma || build_id_parse(vma, id_offs[i].build_id)) { + if (!vma || build_id_parse(vma, id_offs[i].build_id, NULL)) { /* per entry fall back to ips */ id_offs[i].status = BPF_STACK_BUILD_ID_IP; id_offs[i].ip = ips[i]; diff --git a/lib/buildid.c b/lib/buildid.c index 4a4f520c0e29..6156997c3895 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -12,6 +12,7 @@ */ static inline int parse_build_id(void *page_addr, unsigned char *build_id, + __u32 *size, void *note_start, Elf32_Word note_size) { @@ -38,6 +39,8 @@ static inline int parse_build_id(void *page_addr, nhdr->n_descsz); memset(build_id + nhdr->n_descsz, 0, BUILD_ID_SIZE_MAX - nhdr->n_descsz); + if (size) + *size = nhdr->n_descsz; return 0; } new_offs = note_offs + sizeof(Elf32_Nhdr) + @@ -50,7 +53,8 @@ static inline int parse_build_id(void *page_addr, } /* Parse build ID from 32-bit ELF */ -static int get_build_id_32(void *page_addr, unsigned char *build_id) +static int get_build_id_32(void *page_addr, unsigned char *build_id, + __u32 *size) { Elf32_Ehdr *ehdr = (Elf32_Ehdr *)page_addr; Elf32_Phdr *phdr; @@ -65,7 +69,7 @@ static int get_build_id_32(void *page_addr, unsigned char *build_id) for (i = 0; i < ehdr->e_phnum; ++i) { if (phdr[i].p_type == PT_NOTE && - !parse_build_id(page_addr, build_id, + !parse_build_id(page_addr, build_id, size, page_addr + phdr[i].p_offset, phdr[i].p_filesz)) return 0; @@ -74,7 +78,8 @@ static int get_build_id_32(void *page_addr, unsigned char *build_id) } /* Parse build ID from 64-bit ELF */ -static int get_build_id_64(void *page_addr, unsigned char *build_id) +static int get_build_id_64(void *page_addr, unsigned char *build_id, + __u32 *size) { Elf64_Ehdr *ehdr = (Elf64_Ehdr *)page_addr; Elf64_Phdr *phdr; @@ -89,7 +94,7 @@ static int get_build_id_64(void *page_addr, unsigned char *build_id) for (i = 0; i < ehdr->e_phnum; ++i) { if (phdr[i].p_type == PT_NOTE && - !parse_build_id(page_addr, build_id, + !parse_build_id(page_addr, build_id, size, page_addr + phdr[i].p_offset, phdr[i].p_filesz)) return 0; @@ -97,8 +102,16 @@ static int get_build_id_64(void *page_addr, unsigned char *build_id) return -EINVAL; } -/* Parse build ID of ELF file mapped to vma */ -int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id) +/* + * Parse build ID of ELF file mapped to vma + * @vma: vma object + * @build_id: buffer to store build id, at least BUILD_ID_SIZE long + * @size: returns actual build id size in case of success + * + * Returns 0 on success, otherwise error (< 0). + */ +int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, + __u32 *size) { Elf32_Ehdr *ehdr; struct page *page; @@ -126,9 +139,9 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id) goto out; if (ehdr->e_ident[EI_CLASS] == ELFCLASS32) - ret = get_build_id_32(page_addr, build_id); + ret = get_build_id_32(page_addr, build_id, size); else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) - ret = get_build_id_64(page_addr, build_id); + ret = get_build_id_64(page_addr, build_id, size); out: kunmap_atomic(page_addr); put_page(page); -- 2.26.2