From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752589AbbE1DfM (ORCPT ); Wed, 27 May 2015 23:35:12 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:23926 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751207AbbE1DfH (ORCPT ); Wed, 27 May 2015 23:35:07 -0400 Message-ID: <55668CCD.9040506@huawei.com> Date: Thu, 28 May 2015 11:34:37 +0800 From: "Wangnan (F)" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Alexei Starovoitov CC: , , , , , , , , , , , , Subject: Re: [RFC PATCH v4 09/29] bpf tools: Collect version and license from ELF sections References: <1432704004-171454-1-git-send-email-wangnan0@huawei.com> <1432704004-171454-10-git-send-email-wangnan0@huawei.com> <20150528014818.GD20764@Alexeis-MacBook-Pro.local> In-Reply-To: <20150528014818.GD20764@Alexeis-MacBook-Pro.local> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2015/5/28 9:48, Alexei Starovoitov wrote: > On Wed, May 27, 2015 at 05:19:44AM +0000, Wang Nan wrote: >> Expand bpf_obj_elf_collect() to collect license and kernel version >> information in eBPF object file. eBPF object file should have a section >> named 'license', which contains a string. It should also have a section >> named 'version', contains a u32 LINUX_VERSION_CODE. >> >> bpf_obj_validate() is introduced to validate object file after loaded. >> Currently it only check existance of 'version' section. >> >> Signed-off-by: Wang Nan >> --- > ... >> +static int >> +bpf_object__init_kversion(struct bpf_object *obj, >> + void *data, size_t size) >> +{ >> + u32 kver; >> + if (size < sizeof(kver)) { > shouldn't it be '!=' ? Is it possible that LLVM pads 'version' section so the size of it becomes longer than sizeof(u32)? Thank you. >> + pr_warning("invalid kver section in %s\n", obj->path); >> + return -EINVAL; >> + } >> + memcpy(&kver, data, sizeof(kver)); >> + obj->kern_version = kver; >> + pr_debug("kernel version of %s is %x\n", obj->path, >> + obj->kern_version); >> + return 0; >> +} >> +