| Message ID | 87pl073358.fsf@redhat.com |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F3D84BA2E27 for <patchwork@sourceware.org>; Tue, 28 Jul 2026 08:55:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F3D84BA2E27 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GU+g/wZm X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 1B8634BA2E27 for <binutils@sourceware.org>; Tue, 28 Jul 2026 08:54:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B8634BA2E27 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B8634BA2E27 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785228894; cv=none; b=nLzPgLirBPy/PTbPW+Y3vLfAK9Tce6BczJ4NgNEzlipJU5qd0eFnG3NEExbn6gvCsC5+uYO0MxoDEpDSUp4dikxisTTmaezFKJkH4tZVz7XpPUvY37neCvjcEE98AZZiwjbToZy7vLZ2Pj9jZSnV0dCXROyefJVpR4+GsGyaqew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785228894; c=relaxed/simple; bh=1m4IBkY99Vwjfgf9OhdHTlQjRdsPnt3ACOR3kH7SbI0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Kv6koa/F1DAfjv93WWSUHPl0kh/mUgWG/k6fLcQyA9zBqMyhw6aZzM+rGJILcLciInn4z6KuIn7fK33wG38NKUX/u5XWowN3jmTpYwl2ozRv+RjvNdE+/QDEnPWBQpm3A9qvP81k5H3527Rso2LNcO+kGjizUueTpga6UapT06Y= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GU+g/wZm DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B8634BA2E27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785228893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2fuUgeyOvXhfcjDOaooaj7T50b21SnFm+Jm/17aD+vg=; b=GU+g/wZm8ZCERLM0pSwbwe/hE/LNOL5IeqBab2yvhLmHgu+ElYHSC+gGN2+iXwfjDwwfWy q6RAl2lkiybyQl6AFxDGAomUiy29jhFR7OeGPxD92vRp8Vb8E1aTpwpTMy4q68YeUFKx/S mfElVZZvVo1XX4hVnZqvkuJaYseKCPU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-FFRpnO1nOyOXXuc5zMQd0g-1; Tue, 28 Jul 2026 04:54:49 -0400 X-MC-Unique: FFRpnO1nOyOXXuc5zMQd0g-1 X-Mimecast-MFC-AGG-ID: FFRpnO1nOyOXXuc5zMQd0g_1785228889 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C3A34195608B; Tue, 28 Jul 2026 08:54:48 +0000 (UTC) Received: from prancer.redhat.com (unknown [10.44.49.69]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 849C71956086; Tue, 28 Jul 2026 08:54:46 +0000 (UTC) From: Nick Clifton <nickc@redhat.com> To: ibhagatgnu@gmail.com Cc: binutils@sourceware.org Subject: RFA: Fix potential memory leak in gen-sframe.c Date: Tue, 28 Jul 2026 09:54:43 +0100 Message-ID: <87pl073358.fsf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SqRTkVwklRgghocNbPiytFbDK4hGTkE4mTaAFVjLImg_1785228889 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
RFA: Fix potential memory leak in gen-sframe.c
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_binutils_build--master-arm | success | Build passed |
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 | success | Build passed |
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 | success | Test passed |
| linaro-tcwg-bot/tcwg_binutils_check--master-arm | success | Test passed |
Commit Message
Nick Clifton
July 28, 2026, 8:54 a.m. UTC
Hi Indu,
Is the patch below OK ? It updates the sframe_xlate_ctx_cleanup()
function so that it also zeroes out the other fields in the
sframe_xlate_ctx structure.
Disclaimer: I used an AI tool (claude) to locate the problem being
fixed by this patch, but I wrote the patch myself. Ie I did not use
AI to write the patch.
The problem reported looks like this:
1. sframe_do_fde() (line 2490) populates xlate_ctx->first_fre with
allocated FRE entries and sets xlate_ctx->num_xlate_fres > 0.
2. On failure for a signal frame (line 2491-2496),
sframe_xlate_ctx_cleanup() frees the FRE chain (line 1096) but
does not null first_fre or reset num_xlate_fres. Then err is
forced to SFRAME_XLATE_OK.
3. Since err is now OK, sframe_xlate_ctx_finalize() (line 2507)
copies the dangling first_fre pointer and stale count into the
output SFrame FDE structure.
4. The FDE with dangling pointer is linked into the output list
(lines 2508-2509) and its freed data is later written to the
output .sframe section.
So, do you agree with this analysis and is the proposed patch a
sufficient solution ?
Cheers
Nick
Comments
On 7/28/2026 10:54 AM, Nick Clifton wrote: > Hi Indu, > > Is the patch below OK ? It updates the sframe_xlate_ctx_cleanup() > function so that it also zeroes out the other fields in the > sframe_xlate_ctx structure. > > Disclaimer: I used an AI tool (claude) to locate the problem being > fixed by this patch, but I wrote the patch myself. Ie I did not use > AI to write the patch. > > The problem reported looks like this: > > 1. sframe_do_fde() (line 2490) populates xlate_ctx->first_fre with > allocated FRE entries and sets xlate_ctx->num_xlate_fres > 0. > > 2. On failure for a signal frame (line 2491-2496), > sframe_xlate_ctx_cleanup() frees the FRE chain (line 1096) but > does not null first_fre or reset num_xlate_fres. Then err is > forced to SFRAME_XLATE_OK. > > 3. Since err is now OK, sframe_xlate_ctx_finalize() (line 2507) > copies the dangling first_fre pointer and stale count into the > output SFrame FDE structure. > > 4. The FDE with dangling pointer is linked into the output list > (lines 2508-2509) and its freed data is later written to the > output .sframe section. > > So, do you agree with this analysis and is the proposed patch a > sufficient solution ? Not Indu, but replying as I was involved in SFrame V3 development: I can confirm that above causes a segmentation fault and below fixes it. See my just sent "[PATCH 0/2] gas: sframe: Fix for flefible FDE and new test": https://inbox.sourceware.org/binutils/20260729163445.2563223-1-jremus@linux.ibm.com/ > diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c > index b5c8f649bea..6d1cafa63bf 100644 > --- a/gas/gen-sframe.c > +++ b/gas/gen-sframe.c > @@ -1094,6 +1094,9 @@ static void > sframe_xlate_ctx_cleanup (struct sframe_xlate_ctx *xlate_ctx) > { > sframe_row_entry_free (xlate_ctx->first_fre); > + xlate_ctx->first_fre = NULL; > + xlate_ctx->last_fre = NULL; > + xlate_ctx->num_xlate_fres = 0; > XDELETE (xlate_ctx->remember_fre); > xlate_ctx->remember_fre = NULL; > XDELETE (xlate_ctx->cur_fre); Maybe also reset the flexible FDE flag: xlate_ctx->flex_p = false; Regards, Jens
Hi Jens, > Maybe also reset the flexible FDE flag: > > xlate_ctx->flex_p = false; Good idea. I have applied that change with that addition. Cheers Nick
diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index b5c8f649bea..6d1cafa63bf 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -1094,6 +1094,9 @@ static void sframe_xlate_ctx_cleanup (struct sframe_xlate_ctx *xlate_ctx) { sframe_row_entry_free (xlate_ctx->first_fre); + xlate_ctx->first_fre = NULL; + xlate_ctx->last_fre = NULL; + xlate_ctx->num_xlate_fres = 0; XDELETE (xlate_ctx->remember_fre); xlate_ctx->remember_fre = NULL; XDELETE (xlate_ctx->cur_fre);