From patchwork Wed Apr 22 10:28:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 1274917 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=eyPNSVB8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 496cCv4zWLz9sT1 for ; Wed, 22 Apr 2020 20:31:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731055AbgDVKa5 (ORCPT ); Wed, 22 Apr 2020 06:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731003AbgDVK2b (ORCPT ); Wed, 22 Apr 2020 06:28:31 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 114C9C03C1AA for ; Wed, 22 Apr 2020 03:28:31 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id t3so1830721qkg.1 for ; Wed, 22 Apr 2020 03:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hy/Ktw/WIQpfzZT8igDmzHAnYkpUxpGcZah1zMZs3z8=; b=eyPNSVB8V6Wn1vYjmCc9ZBz8w7d2+TTjkMQKOODE4x7YWPiSUg2KbT1I7Xqh+RkxDx ZrznN86hSflt30MqRWhZ4vSXCfyh34GhNduBb1dgSPowrznwc6QSwkOzs6VpXA5PE8qU P4UgF2wkOU54VspXGGkU3bVLh9X0EOoR/T96DWVIwSfcCd2c5nG/L2KmgGIcB9wlSM9q Nu1kGfmyO3KqUi6PReOxxnk1eO1NibCYTGomXHkg+IKTB74qY8LwIanlQKe4IwBPrv4i QwFfqLQ+7j7AzYG2VRDO9rJ/TBenTZ8iMm/sPOpSAK4g9tnL4gvEvW5DhcTdF9K2alyS DDBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hy/Ktw/WIQpfzZT8igDmzHAnYkpUxpGcZah1zMZs3z8=; b=txJepyfbd6/u6XFMvYOM6AHbtc3zX1zGM8ExYl6+Z7QPIwVmNd6yvGWvxOmrZyMzdK bBbbg3ZYCsZkoFcA5EDrLi8BIb9iTzFdzG7O9Yth3d0S+LTWp+RSTAww44PZfS4Sa9r3 +xcbVO5D6WsQuaLkUHtFr1VJEfKaMDSI73t6JIPc7IFmYbfGvkhXdTBiyR8iShTsptv9 WHMXTwgpYeVbE3C6HdedKjWJl5dN3jUxS5i1v2YYB9BYoENd0iqNszUOSCItACfk3o3H xY3kyhEUNBf7AduJcN/Jki3+1gRKOKAZXf8hf2EKJbcwkNrxyR+3bx5j4L5Bk88BswVb o2dA== X-Gm-Message-State: AGi0PuaUm+Km0FmcmZ+B7lUVNUEkZLVfHZpXip9/oLORE+I9WukKdr2T Q4i+l87hiJNPePhK7INfkIgYkw== X-Google-Smtp-Source: APiQypKEXAwNBiQJBYoyktH0un2zQu8I8qmzoAYP6ZZMeXe+UdPEUcHsJP6GCJgRQX4wEEeSWmQaVQ== X-Received: by 2002:a37:7a85:: with SMTP id v127mr15782329qkc.385.1587551310366; Wed, 22 Apr 2020 03:28:30 -0700 (PDT) Received: from localhost.localdomain (23-233-27-60.cpe.pppoe.ca. [23.233.27.60]) by smtp.gmail.com with ESMTPSA id h3sm3531964qkf.15.2020.04.22.03.28.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2020 03:28:29 -0700 (PDT) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: stephen@networkplumber.org Cc: netdev@vger.kernel.org, dsahern@gmail.com, aclaudi@redhat.com, daniel@iogearbox.net, asmadeus@codewreck.org, Jamal Hadi Salim , Jamal Hadi Salim Subject: [PATCH iproute2 v2 1/2] bpf: Fix segfault when custom pinning is used Date: Wed, 22 Apr 2020 06:28:07 -0400 Message-Id: <20200422102808.9197-2-jhs@emojatatu.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422102808.9197-1-jhs@emojatatu.com> References: <20200422102808.9197-1-jhs@emojatatu.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim Fixes: c0325b06382 ("bpf: replace snprintf with asprintf when dealing with long buffers") Signed-off-by: Jamal Hadi Salim --- lib/bpf.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/bpf.c b/lib/bpf.c index 10cf9bf4..656cad02 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -1509,15 +1509,15 @@ out: static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx, const char *todo) { - char *tmp = NULL; + char tmp[PATH_MAX] = {}; char *rem = NULL; char *sub; int ret; - ret = asprintf(&tmp, "%s/../", bpf_get_work_dir(ctx->type)); + ret = snprintf(tmp, PATH_MAX, "%s/../", bpf_get_work_dir(ctx->type)); if (ret < 0) { - fprintf(stderr, "asprintf failed: %s\n", strerror(errno)); - goto out; + fprintf(stderr, "snprintf failed: %s\n", strerror(errno)); + return ret; } ret = asprintf(&rem, "%s/", todo); @@ -1547,7 +1547,6 @@ static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx, ret = 0; out: free(rem); - free(tmp); return ret; } From patchwork Wed Apr 22 10:28:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 1274914 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=saYLG70w; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 496cCM5CzBz9sTS for ; Wed, 22 Apr 2020 20:30:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731069AbgDVKa2 (ORCPT ); Wed, 22 Apr 2020 06:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730936AbgDVK2h (ORCPT ); Wed, 22 Apr 2020 06:28:37 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4EAAC03C1AD for ; Wed, 22 Apr 2020 03:28:36 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id g74so1739460qke.13 for ; Wed, 22 Apr 2020 03:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xr1VuRWexFKfZaAUV/+2KBKVKlnxK30XNcZOGdLsaAs=; b=saYLG70wzoX5/JG+Jy6RF/I7U0uJRBIREziPNcgyxxPfIETu2MYJoF4mQ5iKoabrFs bjlImwxh0170HopOS7Y0wdjghujcd0DqysU/PK3a8ueISG29/83NfNF69FM27VcAY8Z1 h7G+AOdKzcF2WLeebzJiP9nf8ns7G79hJvDdzR3SfSY3hMWciXhlUmaK5cjo9TgKCtUb Bt6skC6eCTnloeGtSykz68ST5Xn6bMIfTdiFiT4P/l0q/6JkbX+XNEfoyZCC2q/OpT4n TrvcwIq2w0LoXTxIIS3e6QU3j4dJwFncg1+Q+oW3hSpVOjly2llER2OJwBXaz/YSbQS2 O10A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xr1VuRWexFKfZaAUV/+2KBKVKlnxK30XNcZOGdLsaAs=; b=W/s5eKGoCOp/xTyKzcaJlqnbEnMOrsKns5h3mCEUvV5UsBRHHrT+8qk6gvaHPD1Jz9 nvfxkAhtqFns4Vw+50LrQK3YjdZdbZ9oup8cArlC1rFvMr4vl7tgGbMJZVEXEf5PeV07 rc42njzHwmSQDh4dFVwgQT6/1eqZjRgIXqA00uYE1/d+ARKhrgJQTbbVIml95yh9Ad17 GlSjFio2Gh2uwTJO5UH4L/BCjtxsc/UYZLphH99RjpEjf4n1mVHOPdDfzwrqhKmsR+0X eZo2ODBz1aK44ufq2+1SL4TOia6n3YLTC1BNeLWTodqt2TY6JBuYmmN87Vz71SR68gNV RDEQ== X-Gm-Message-State: AGi0PuZsNM8PyDGppz9R+EQhz3YRiNukg3wdZ6mcsKwpV9VT4OiOK5Ca VKQWuU9KOLqaTgKGPD3HrGr29A== X-Google-Smtp-Source: APiQypJ10zY2TT04i4bA4sun4LJlfGVw72o/o+PLrmWwpJm9ItKAtsUeWLlnNtOGIgZopG8YmyQj2Q== X-Received: by 2002:a37:4015:: with SMTP id n21mr23171912qka.76.1587551316053; Wed, 22 Apr 2020 03:28:36 -0700 (PDT) Received: from localhost.localdomain (23-233-27-60.cpe.pppoe.ca. [23.233.27.60]) by smtp.gmail.com with ESMTPSA id h3sm3531964qkf.15.2020.04.22.03.28.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2020 03:28:35 -0700 (PDT) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: stephen@networkplumber.org Cc: netdev@vger.kernel.org, dsahern@gmail.com, aclaudi@redhat.com, daniel@iogearbox.net, asmadeus@codewreck.org, Jamal Hadi Salim , Jamal Hadi Salim Subject: [PATCH iproute2 v2 2/2] bpf: Fix mem leak and extraneous free() in error path Date: Wed, 22 Apr 2020 06:28:08 -0400 Message-Id: <20200422102808.9197-3-jhs@emojatatu.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422102808.9197-1-jhs@emojatatu.com> References: <20200422102808.9197-1-jhs@emojatatu.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim Fixes: c0325b06382 ("bpf: replace snprintf with asprintf when dealing with long buffers") Signed-off-by: Jamal Hadi Salim --- lib/bpf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/bpf.c b/lib/bpf.c index 656cad02..fdcede1c 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -1523,13 +1523,15 @@ static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx, ret = asprintf(&rem, "%s/", todo); if (ret < 0) { fprintf(stderr, "asprintf failed: %s\n", strerror(errno)); - goto out; + return ret; } sub = strtok(rem, "/"); while (sub) { - if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX) - return -EINVAL; + if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX) { + ret = -EINVAL; + goto out; + } strcat(tmp, sub); strcat(tmp, "/");