Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1762585imu; Wed, 21 Nov 2018 01:21:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/VgiOlftVBoPKl6zR2l9fZmWmb06pfQgXXngFiXzzdkA3NWzzLprjy4vJiIPLicP9MIJOc7 X-Received: by 2002:a63:bf0b:: with SMTP id v11mr5361292pgf.302.1542792104755; Wed, 21 Nov 2018 01:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542792104; cv=none; d=google.com; s=arc-20160816; b=dbeVZJzkUNxmnzlXzY7owgaTI2TyNXOj7jtbnOPrzLQDmA7h4P7vGuo4xhKgdz+JHz cXPKjJ88uBiQ00zKLR17AGYquZogCxHf8RmuInOwuFy40onw4BEyUoOpcEytNvsQ07PX ZUBI2akgK94mc648HvtpnpHfegSPaH7cHTeNmVzjEcX69s8y0pjSvqc4ZWesFzCs1w+P 7t49F57PkF0jGqQEpAxz8UdlZvy11vDn5usHd2r9u17krLFlg+ybs+jV5kdc2NLO/8o0 +XDNO8m90Cn8XTa8hyWQs6TjRoaafZQwse4q7b2SC+/UlTYeslicOaKLKLx76Ffjs1kw l+ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=kASYs5X6WrEmAVTFeTnKQCVrM3/792NwU1zv/+cHsqc=; b=i0IyPx/8VbWX9gWI4clbW+F/gEQGppo6D52VEfGjMEH6mBeSIUS4+5RFtOY9tYyjft d7Npkp+TMZBIcuQt50g8YC+pQcpER5KBmlz9kmU1nEGeYiZaZssXNk7ACXl1Z9Gbopeo efCywkYKyCT8iLrmcOdMZ+QnOdAJyrDkpwwkLz0hMfJs2MMrilU4LQFYU5PjMM5qKB6o NeiVUx7ztSGPDZfjSdDdIkeovvUSmf6liOUhKe/PHvRgNZK9G5D9KME8A3uH5d+V2y53 7noN0ZSejnBHFMIQNlSrAzSx42blLiOG5OOWFSDq+OKV0hcumtDhMBZl2vE7DNUAnUEA UOuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3-v6si12109750pls.137.2018.11.21.01.21.29; Wed, 21 Nov 2018 01:21:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728045AbeKUSPT (ORCPT + 99 others); Wed, 21 Nov 2018 13:15:19 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:33224 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbeKUSPT (ORCPT ); Wed, 21 Nov 2018 13:15:19 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 5722D13616AF56812A6E; Wed, 21 Nov 2018 15:41:49 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wAL7fhR7087238; Wed, 21 Nov 2018 15:41:43 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018112115420546-12071605 ; Wed, 21 Nov 2018 15:42:05 +0800 From: Wen Yang To: ast@kernel.org Cc: daniel@iogearbox.net, jakub.kicinski@netronome.com, quentin.monnet@netronome.com, jiong.wang@netronome.com, guro@fb.com, sandipan@linux.vnet.ibm.com, john.fastabend@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, wang.yi59@zte.com.cn, Wen Yang , Julia Lawall Subject: [PATCH 3/4] tools: bpftool: fix potential NULL pointer dereference in do_load Date: Wed, 21 Nov 2018 15:43:12 +0800 Message-Id: <1542786192-19164-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-11-21 15:42:05, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-11-21 15:41:35, Serialize complete at 2018-11-21 15:41:35 X-MAIL: mse01.zte.com.cn wAL7fhR7087238 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes a possible null pointer dereference in do_load, detected by the semantic patch deref_null.cocci, with the following warning: ./tools/bpf/bpftool/prog.c:1021:23-25: ERROR: map_replace is NULL but dereferenced. The following code has potential null pointer references: 881 map_replace = reallocarray(map_replace, old_map_fds + 1, 882 sizeof(*map_replace)); 883 if (!map_replace) { 884 p_err("mem alloc failed"); 885 goto err_free_reuse_maps; 886 } ... 1019 err_free_reuse_maps: 1020 for (i = 0; i < old_map_fds; i++) 1021 close(map_replace[i].fd); 1022 free(map_replace); Signed-off-by: Wen Yang Reviewed-by: Tan Hu CC: Julia Lawall --- tools/bpf/bpftool/prog.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 5302ee2..de42187 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -1017,8 +1017,9 @@ static int do_load(int argc, char **argv) err_close_obj: bpf_object__close(obj); err_free_reuse_maps: - for (i = 0; i < old_map_fds; i++) - close(map_replace[i].fd); + if (map_replace) + for (i = 0; i < old_map_fds; i++) + close(map_replace[i].fd); free(map_replace); return -1; } -- 2.9.5