From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754621AbcAVRLG (ORCPT ); Fri, 22 Jan 2016 12:11:06 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36118 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754458AbcAVRLD (ORCPT ); Fri, 22 Jan 2016 12:11:03 -0500 Date: Fri, 22 Jan 2016 09:11:03 -0800 From: Alexei Starovoitov To: Wang Nan Cc: ast@kernel.org, acme@kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Daniel Borkmann , Li Zefan , pi3orama@163.com Subject: Re: [PATCH 2/2] perf bpf: Check relocation target section Message-ID: <20160122171102.GB9608@ast-mbp.thefacebook.com> References: <1453454841-232334-1-git-send-email-wangnan0@huawei.com> <1453454841-232334-3-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1453454841-232334-3-git-send-email-wangnan0@huawei.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 22, 2016 at 09:27:21AM +0000, Wang Nan wrote: > Libbpf should check target section before doing relocation to ensure > the relocation is correct. If not, a bug in LLVM causes error. See [1]. > Also, if an incorrect BPF script uses both global variable and > map, global variable whould be treated as map and be relocated > without error. > > This patch saves id of map section into obj->efile and compare > target section of a relocation symbol against it during relocation. ... > [1] https://llvm.org/bugs/show_bug.cgi?id=26243 ... > Signed-off-by: Wang Nan > > + if (sym.st_shndx != maps_shndx) { > + pr_warning("Program '%s' contains non-map related relo data pointing to section %u\n", > + prog->section_name, sym.st_shndx); > + return -LIBBPF_ERRNO__RELOC; > + } May be 'pr_err' instead of 'pr_warning', since such program will fail to load by kernel anyway. Looks good otherwise. Acked-by: Alexei Starovoitov