From patchwork Wed May 23 17:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin KaFai Lau X-Patchwork-Id: 919236 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="gMa/gujS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40rg216851z9s0W for ; Thu, 24 May 2018 03:47:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933912AbeEWRrD (ORCPT ); Wed, 23 May 2018 13:47:03 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:44408 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932592AbeEWRrB (ORCPT ); Wed, 23 May 2018 13:47:01 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4NHh9GL009332 for ; Wed, 23 May 2018 10:47:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=8D5BNL0uBuRlqrhKg+cS/sLSkzjgX4c8kQIRdcP33XU=; b=gMa/gujSzMbgEXHmbQNzL1phlSapWSWRfyFFHc2laoqzAsuUqwQqgeeCEQjuAwfeIWOj +GLiR1TATBcGPKqDT/xy5rcAAP03ypJsSlpE3LOEztF3jWkhf7ud0/5errbodZ/N9VrB DA96zvKhYeZq9i0ChgocVi4DR3u82u+Ji9k= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2j59vwgm2d-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 23 May 2018 10:47:00 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB12.TheFacebook.com (192.168.16.22) with Microsoft SMTP Server id 14.3.319.2; Wed, 23 May 2018 10:46:59 -0700 Received: by devbig005.ftw2.facebook.com (Postfix, from userid 6611) id 5FB412941234; Wed, 23 May 2018 10:46:59 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Martin KaFai Lau Smtp-Origin-Hostname: devbig005.ftw2.facebook.com To: CC: Alexei Starovoitov , Daniel Borkmann , Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next] bpf: btf: Avoid variable length array Date: Wed, 23 May 2018 10:46:59 -0700 Message-ID: <20180523174659.354660-1-kafai@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-23_07:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Sparse warning: kernel/bpf/btf.c:1985:34: warning: Variable length array is used. This patch moves the nr_secs from btf_check_sec_info() to a macro. Fixes: f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header") Signed-off-by: Martin KaFai Lau --- kernel/bpf/btf.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 9cbeabb5aca3..517296712774 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -1970,6 +1970,8 @@ static const size_t btf_sec_info_offset[] = { offsetof(struct btf_header, str_off), }; +#define NR_SECS ARRAY_SIZE(btf_sec_info_offset) + static int btf_sec_info_cmp(const void *a, const void *b) { const struct btf_sec_info *x = a; @@ -1981,8 +1983,7 @@ static int btf_sec_info_cmp(const void *a, const void *b) static int btf_check_sec_info(struct btf_verifier_env *env, u32 btf_data_size) { - const unsigned int nr_secs = ARRAY_SIZE(btf_sec_info_offset); - struct btf_sec_info secs[nr_secs]; + struct btf_sec_info secs[NR_SECS]; u32 total, expected_total, i; const struct btf_header *hdr; const struct btf *btf; @@ -1991,17 +1992,17 @@ static int btf_check_sec_info(struct btf_verifier_env *env, hdr = &btf->hdr; /* Populate the secs from hdr */ - for (i = 0; i < nr_secs; i++) + for (i = 0; i < NR_SECS; i++) secs[i] = *(struct btf_sec_info *)((void *)hdr + btf_sec_info_offset[i]); - sort(secs, nr_secs, sizeof(struct btf_sec_info), + sort(secs, NR_SECS, sizeof(struct btf_sec_info), btf_sec_info_cmp, NULL); /* Check for gaps and overlap among sections */ total = 0; expected_total = btf_data_size - hdr->hdr_len; - for (i = 0; i < nr_secs; i++) { + for (i = 0; i < NR_SECS; i++) { if (expected_total < secs[i].off) { btf_verifier_log(env, "Invalid section offset"); return -EINVAL;