Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1046412ybj; Thu, 7 May 2020 13:32:42 -0700 (PDT) X-Google-Smtp-Source: APiQypK9LBT/o2ILlmysYsFmYikLoRpoOwlLvntAC8AH3YdvY3EzBN0VFs92oPzzqYB+muaqoIJ7 X-Received: by 2002:a50:e8c1:: with SMTP id l1mr14170137edn.81.1588883562287; Thu, 07 May 2020 13:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588883562; cv=none; d=google.com; s=arc-20160816; b=wi16n7SYIBknYfCCLBCUmV8gD5S3PonhCHs/PP8nmfD06IZhaYXrMs5MlPysNLw9xP sfFZjUUCd+aY3DUQ4Bc5G6XUlmwF/8ORZn+Kpc9HJBSvVUnDt9IBJJUEIWw3sCZ5H7Cn UBh8aybbvPd3wBcHrUdb+T9NbcIQqgRiMcm01fnzlHodOz+u6HtwDjBcBDcJikMkt2Ho TdnMMixzWpag81XnDR3yAM8s/JkoT++6IN6GKdEtodgI4zp6bwfsExJtPYeigm8vqGf3 CBJJQi/ajeKnrnf2yx6F8D5kgzMCY+/m9Z9HHBYmb+lMOi208fQ1TJnPMieyWZdWAOSG JWXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:autocrypt :from:subject:cc:to:dkim-signature; bh=1DnuwWuXsZL+agQraBsdh6zbOfEgnKt0ONdD5cOITLA=; b=bXHGO+vx5/j7IBLb1Obu0TVtoyQ02mhXH66XH9T4aVH85+sRzFRh/glw5ja+K8cdNU rmLvorhBslGPQV1cC9GJgp0Eidwf+ADstd84zvGm6rJGT8M6DL2AtovS/AHxcLRMSwD0 8MOwnwIiQutiefVyTntf/tcjDl3k5f0ocqmtkPlxrV65es0/YRUSkrN88e2EEpO5GuU4 +dMhtFotMX6Ui/MBPMSLZ4g7IhazUzO/Y/lJ6Rs5YopDB1TGT7pt+k/v21SsGUUPy4rR t2II0szbW/XaAzJ2YHuGTRO8XI5EybU45GwOqqoXa8YsNZjmLgT0kxdgNP2suCipEvCa BNXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=dbaedf251592 header.b=CgX1hfmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck25si3902056ejb.114.2020.05.07.13.32.19; Thu, 07 May 2020 13:32:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=dbaedf251592 header.b=CgX1hfmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726575AbgEGUaw (ORCPT + 99 others); Thu, 7 May 2020 16:30:52 -0400 Received: from mout.web.de ([212.227.15.4]:46871 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbgEGUaw (ORCPT ); Thu, 7 May 2020 16:30:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1588883413; bh=q60NAPu4JTUrRuU60qiN+V5aGjYCl6aKIElHv/6o4kg=; h=X-UI-Sender-Class:To:Cc:Subject:From:Date; b=CgX1hfmUsIujjPH7cZTeiJXtQVndukpjLbIxu1qnPdikdA00pO/RMNVLdK26+wQp0 Nykh6CCBn7nF2lXP+6R1c/Ohgai+xlaNodnDnk7gDqf0aAi9g/GmrZ16oR+UbWPDNR 9bjrL6FpowXC8UD9FBJUmq+vJEPmwdkitRlDd3Dw= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.1.2] ([93.132.29.220]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Mb8h9-1jrKog0dB5-00KdLe; Thu, 07 May 2020 22:30:13 +0200 To: Yunfeng Ye , Steven Rostedt , Masami Hiramatsu Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Hewenliang , Shiyuan Hu Subject: Re: [PATCH] tools/bootconfig: fix resource leak in apply_xbc() From: Markus Elfring Autocrypt: addr=Markus.Elfring@web.de; prefer-encrypt=mutual; keydata= mQINBFg2+xABEADBJW2hoUoFXVFWTeKbqqif8VjszdMkriilx90WB5c0ddWQX14h6w5bT/A8 +v43YoGpDNyhgA0w9CEhuwfZrE91GocMtjLO67TAc2i2nxMc/FJRDI0OemO4VJ9RwID6ltwt mpVJgXGKkNJ1ey+QOXouzlErVvE2fRh+KXXN1Q7fSmTJlAW9XJYHS3BDHb0uRpymRSX3O+E2 lA87C7R8qAigPDZi6Z7UmwIA83ZMKXQ5stA0lhPyYgQcM7fh7V4ZYhnR0I5/qkUoxKpqaYLp YHBczVP+Zx/zHOM0KQphOMbU7X3c1pmMruoe6ti9uZzqZSLsF+NKXFEPBS665tQr66HJvZvY GMDlntZFAZ6xQvCC1r3MGoxEC1tuEa24vPCC9RZ9wk2sY5Csbva0WwYv3WKRZZBv8eIhGMxs rcpeGShRFyZ/0BYO53wZAPV1pEhGLLxd8eLN/nEWjJE0ejakPC1H/mt5F+yQBJAzz9JzbToU 5jKLu0SugNI18MspJut8AiA1M44CIWrNHXvWsQ+nnBKHDHHYZu7MoXlOmB32ndsfPthR3GSv jN7YD4Ad724H8fhRijmC1+RpuSce7w2JLj5cYj4MlccmNb8YUxsE8brY2WkXQYS8Ivse39MX BE66MQN0r5DQ6oqgoJ4gHIVBUv/ZwgcmUNS5gQkNCFA0dWXznQARAQABtCZNYXJrdXMgRWxm cmluZyA8TWFya3VzLkVsZnJpbmdAd2ViL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HmSuU3JSAMB/N+yQjIad2ztTckZY pwT6oxng29LzZspTYUEzMz3wK2jQHw+U66qBFk8whA7B2uAU1QdGyPgahLYSOa4XAEGb6wbI FEE= Message-ID: <63755ce8-5e1b-6c54-2f74-649cc2546371@web.de> Date: Thu, 7 May 2020 22:30:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:PVpRxJYeS7yQVoNUDAga99j20ZbPA9xj+AB8inkbm8kgT/QzZ/K o+fDq3EA6YZe9rnoyhYMb/ypsBfYfi1cIV4kxzCXd2ibl5ydNMaTX6K2e6V8I1xqxZmgiRN /NhPCznR779J5OTsDTwuoeBsuN/XOhTTzNs1dFMQl9gYI8RYbQnxE/LjPoHOcAfUEwXOiN1 3sB0d52Lj5T5m/y1JRn+A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:zco9H5dHjvY=:4HlzXo6lhw19tiwTI3254O UsjDsyVBa2aRXhms9EraGDB4/LFjDCez2BmDZ8RcGKFigMTBPFtZSk8R4pZ71kKpBZDkTn7WS nssdDt/ouy11RKWto1JeBO9IDMuE5HzPIVhRtgqPN4puKAA7YihArOyG0iusDP1P9Um3H8VL0 Ir0dT+7Nt6hioyaGvCvRxnqXtsWQrxZgGeQI4x1KZBC/KIAi+TZwYsllN+K7S7iYCCPAQ/I9P Aq3xB9j04vaJKn7563sJqXs0Tg3RfWDU8bcMj0KQ2pcgq/BImiTOwTH3wHGUFRy3hBLk/H2vW 515vqu14ejEks1PK39R8yMsOf0wPXSl8LheIcnKFTwAEmYKVUmiu1Ev4bVu+/CqEZ45GAW8fY j15FrpGrdzsMwHv8syPky5pZ3a0+Rg8MUaR/rfa1BK6R1w13JLylRTKlWPrTVPIs9CqFZh6eH 96inEPcNEexxQcW28LlNpVRaFAxIKiIv5h2FFbQRztqWq+3+jqOq2AOTCqo3FKNuJiE+AuOya VXOdeMR24ApQ45pMIk6izGXISs8gCrjWHl+MWiTFXTgwns5eWhHEGItY1GGQ5mqW+UQ91ZQxQ fl2o+YMn4x4th975OHDuI4DK0LoBYk4VRVlZ7lQRT5DXhJ5r6ypHnIGy7GrCdVZ44pirJgKXA W40Z5mGp21rdZcfzjGv2N238Nv/4pf+won+qmXlADeiFUQ2zC+y0ft75t0UPsEZwHrM2dw7wd xg08IJrdclVgxJBSuzKM+b11p1SCCv14ZWQxcUxTZlZ8cfcg8yqf6MnPKj8LvpIB1V60j9V/C DwrDtG0WXk7U6zmwa5c4nqxw86bxa2gw1r9/cjmVRa97WCRg8tO7ezHEactRmITvsXIQ3LccU LZU84NFo0S1d1OjhBKudWDrBneS5EbFWzRPYz/7tUhWYVnFJYrE/8GXRjsraD8J6tLiF8JmjF /KpJMdLzM9bdxpCqYtZDZlWe1sNVdM3iTDQYI3Pz79lxtb6f58kndzrYRKNJeVYt+bN4JpfCg n4+2WDPM7ur9oIlmLISamJLYt1JazBegt+vxKsfy8sDZZhruUHlOzXnD/9vQKx26sS9q8fqPs kZkJmtxZJtnKSnxgS3QkNIRtkEFty3pyH7xsAGLl3LwzS4rcZhuqXJ8KGqyLyvNkOBwVvjDbX E/sOSc/jFg1KvlPwU3/I6ywODfGPeRCiEGQwCvb/Y3PRetq7EYu02hl8IPUycWAH8HG8gIa2U CuAzSFZWsNSDPVPGY Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > The @data and @fd is leak in the error path of apply_xbc(), so this > patch fix it. I suggest to improve this change description. * Please use an imperative wording. * Would you like to add the tag =E2=80=9CFixes=E2=80=9D? > +++ b/tools/bootconfig/main.c > @@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_pat= h) > ret =3D delete_xbc(path); > if (ret < 0) { > pr_err("Failed to delete previous boot config: %d\n", ret); > + free(data); > return ret; > } I propose to adjust the exception handling. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Do= cumentation/process/coding-style.rst?id=3D6e7f2eacf09811d092c1b41263108ac7= fe0d089d#n450 - return ret; + goto free_data; > @@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_pa= th) > fd =3D open(path, O_RDWR | O_APPEND); > if (fd < 0) { > pr_err("Failed to open %s: %d\n", path, fd); > + free(data); > return fd; - return fd; + ret =3D fd; + goto free_data; > } > /* TODO: Ensure the @path is initramfs/initrd image */ > ret =3D write(fd, data, size + 8); > if (ret < 0) { > pr_err("Failed to apply a boot config: %d\n", ret); > - return ret; > + goto out; + goto free_data; > } > /* Write a magic word of the bootconfig */ > ret =3D write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); > if (ret < 0) { - if (ret < 0) { + if (ret < 0) > pr_err("Failed to apply a boot config magic: %d\n", ret); > - return ret; > + goto out; I suggest to avoid an extra jump at such a place. > } - } + > +out: +close_fd: > close(fd); +free_data: > free(data); How do you think about to complete the error handling also at other source code places? Regards, Markus