From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1205331281C for ; Mon, 19 Jan 2026 12:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768826304; cv=none; b=AumtGFEURCINgGqRgkUKe16UyVttpQODun6XLU0I92vCkWCL1+l1lxmKUuAkxeCy6/iBU3G9AGaDhjD5RVH9WZD1rtqvGnc+FUl/mi5N3KCmTENqGzEJHsLp8NBz3LdEm5EjOxxXi0QsjyAcdpB+bjN3tElsMk3wFoSOtwseEF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768826304; c=relaxed/simple; bh=EuiNl9cihI+hXJbn9hHlweZYYYRzfEp6CMDbVm2laFI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h934zOYYKFDbPNp5DTWVTc5ebJL3kFhs7xgj9pcuBSU64Pr8oHPpf4DBKme8qfHujp4Y6DTmZnn3xoJHAc+/Y4Hdf0XpikpJ2dnB8lw2CluWdn3LjagDrcIvYKBGzSSZPKEIhOvs0bvlN6YAO/Bm9jpDux39Xt7lkVsPEf4o/0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=TPLCYOMz; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="TPLCYOMz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=YSltwU8KIfilDQkpyQhBZiIisD3mfXBcQjETEd9fRT4=; b=TPLCYOMztfnU3JUb8tm7zOyNx7 9MHmWXIPebheMnsRISPpcdEFk2jkkWif+agLL1iuMG4UNs76UEFVpHuEamjYoNup2vimiARlHhW7V i/ZqnzVXCFDBLDri8GXIZYh/LHCa1aR5DsAHsHg8hHMn0O2N9TJ9WrnxBbDLT/5B1+5voEZ9WNFQa +pH+hLcOAih/cvycFRhXY+kHxL6f7pm+ZesbiTCQBbBmlzjAkKcP6r8/9bRj9Y3KLOSmpqiNdCWyU 6bTPyZ8TNTGwX8dH8FDhnifzenX0wEgFaM0cVJKdCECRF/Cd5gwd7LMdvbahZhFvh3E0TmlBNEgus giSgh9Iw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vhoWS-0000000C5oO-1DFb; Mon, 19 Jan 2026 12:38:20 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id CDAE53006CD; Mon, 19 Jan 2026 13:38:09 +0100 (CET) Date: Mon, 19 Jan 2026 13:38:09 +0100 From: Peter Zijlstra To: Weigang He Cc: Josh Poimboeuf , linux-kernel@vger.kernel.org Subject: Re: [PATCH] objtool: Fix memory leak in elf_alloc_reloc() on realloc failure Message-ID: <20260119123809.GS830755@noisy.programming.kicks-ass.net> References: <20260118065643.924837-1-geoffreyhe2@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260118065643.924837-1-geoffreyhe2@gmail.com> On Sun, Jan 18, 2026 at 06:56:43AM +0000, Weigang He wrote: > When realloc() fails in elf_alloc_reloc(), the original buffer pointer > is overwritten with NULL before the failure is detected. This causes > the original buffer to become unreachable, resulting in a memory leak. > > Fix this by using a temporary variable to hold the realloc() result. > If realloc() fails, free the original buffer and set d_buf to NULL to > maintain the expected error state before returning -1. > > This bug is found by my static analysis tool and my code review. Yeah, except that the moment this error is actually hit, the tool will exit, freeing all memory.