Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp392116imn; Wed, 27 Jul 2022 09:03:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1usHGwTm1x9uhG8KSYgdMab/Yw6XobKD8GSjVIYPejrzBpwjkCa7tngt5bVZTewioailDJX X-Received: by 2002:a17:90b:1c81:b0:1f1:aa6a:82d0 with SMTP id oo1-20020a17090b1c8100b001f1aa6a82d0mr5480128pjb.170.1658937815181; Wed, 27 Jul 2022 09:03:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658937815; cv=none; d=google.com; s=arc-20160816; b=iK83Dyn5hYgPSf2ANDabSse8MSg3VDYjlKQCLsvqt8cx8mCnkau/zC1Oj3v7ZUhZ/U C7daP5I0+67b01b/3JPVMQaw6Jn+7cH5odqhCrxKNY/WdNF0L1a9LQbgOySmvzNL6sat zqqJ3ARPLINI50bQ4IlMYVio5tIJwFZSObn3NsJEOqHjobKTe6kywYLQfYE5OLErk7QY E1z9wsCGniOL/f7Hoa0CHIH1zQ2JYsmJQZjqyNCOj9w/+/xAR3zaA62MNmjoGmcpv4rc zMPFa4wgEX6R/Fqh69m5+KOoqKLxBA6Wors2ZkP61JqsRvK4Uc20mqIRK45frebFcllF CDYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mTOkhuhtjxHhceipcQ7Kj+QVGW4lNnO3SXS9uBa2HPc=; b=c5Fo4EBFkNRzjha/gehnORKfddYxUgueKvjWrjrfylPkouIObHX3V9EryRB6j1eFI3 0aZ35o4BO4nlUwGbqJq+MZsSG87LVTfxyTFBObTZMhxrI36/PMR3pe9RS0pdTpJrXsX2 wYM7R3hmbYkoUO57FbvXs2Jp2FHZGL9X6kHGZhiHIXVT9LDnyynW/u7P2jF89xZrtdZu jw5YZ7570mgspJVkyePeFPKEqF6WI4g2jRfl6cXA4eaURxmFrxfbdPVL3qKkatQkWB8R jgFfyvhykDa5LGUooa9zzVImltJAyrGQ9QqK6kE7tl3A18Cdt2/jRiZ65tb+/s39y0cX 6j3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020a170902e88500b0016bdabd1eb2si8631951plg.389.2022.07.27.09.03.18; Wed, 27 Jul 2022 09:03:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234048AbiG0Psg (ORCPT + 99 others); Wed, 27 Jul 2022 11:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232787AbiG0Psf (ORCPT ); Wed, 27 Jul 2022 11:48:35 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDE7491E8 for ; Wed, 27 Jul 2022 08:48:33 -0700 (PDT) Received: from stanislav-HLY-WX9XX.. (unknown [46.172.13.9]) by mail.ispras.ru (Postfix) with ESMTPSA id 6D0FF40737A5; Wed, 27 Jul 2022 15:48:29 +0000 (UTC) From: Stanislav Goriainov To: Josh Poimboeuf Cc: Stanislav Goriainov , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] objtool: Fix memory leak in create_static_call_section() Date: Wed, 27 Jul 2022 18:48:25 +0300 Message-Id: <20220727154825.3427-1-goriainov@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some paths of function create_static_call_section() the memory, allocated for key_name via strdup(), is not freed. Even though this is a utility function, and all memory will be freed automatically after the process is finished, there is free(key_sym) in some cases, so it would be sensible to always deallocate the memory. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 1e7e47883830 ("x86/static_call: Add inline static call implementation for x86-64") Signed-off-by: Stanislav Goriainov --- tools/objtool/check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b341f8a8c7c5..abbb3ab8b263 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -666,6 +666,7 @@ static int create_static_call_sections(struct objtool_file *file) if (strncmp(key_name, STATIC_CALL_TRAMP_PREFIX_STR, STATIC_CALL_TRAMP_PREFIX_LEN)) { WARN("static_call: trampoline name malformed: %s", key_name); + free(key_name); return -1; } tmp = key_name + STATIC_CALL_TRAMP_PREFIX_LEN - STATIC_CALL_KEY_PREFIX_LEN; @@ -675,6 +676,7 @@ static int create_static_call_sections(struct objtool_file *file) if (!key_sym) { if (!opts.module) { WARN("static_call: can't find static_call_key symbol: %s", tmp); + free(key_name); return -1; } -- 2.34.1