🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #3050

Bug#1152875: libsnmp-perl: use-after-free when an async request is retried

#3050
From: Sebastian Bugge
Date: Mon, 02 Nov 2026 20:00
104 lines
5388 bytes
Package: libsnmp-perl
Version: 5.9.4+dfsg-2+deb13u1
Severity: important
Tags: patch

Dear Maintainer,

When the `get` method of an SNMP::Session object is retried in an async
context, the callback data is prematurely freed. This is due to treating
the operation NETSNMP_CALLBACK_OP_RESEND as a final operation even though
it is only meant to signify a retry.

This bug can be reproduced by running this script without having a snmp
listener at port 8000:

```perl
#!/usr/bin/perl
use strict;
use warnings;

use SNMP;
use Time::HiRes qw(time);

my $s = SNMP::Session->new(
    DestHost => 'localhost:8000',
    Version  => '2c',
    Timeout  => 200_000,
    Retries  => 1,
);

my $t0 = time;
$s->get(
    [ ['.1.3.6.1.2.1.1'] ],
    [ sub { printf "callback at %.2fs: %s\n", time - $t0, $s->{ErrorStr} } ]
);
SNMP::MainLoop(1);
```

Here is an excerpt from the output when running this script under
valgrind:

```
$ valgrind -q perl reproduction_get.pl
==3412770== Invalid read of size 8
==3412770==    at 0x5FB2261: __snmp_xs_cb (SNMP.xs:1178)
==3412770==    by 0x56D1986: snmp_sess_timeout (snmp_api.c:6881)
==3412770==    by 0x56D1B47: snmp_timeout (snmp_api.c:6726)
==3412770==    by 0x5FB1418: XS_SNMP__main_loop (SNMP.xs:5067)
==3412770==    ...
==3412770==  Address 0x6b8d728 is 8 bytes inside a block of size 16 free'd
==3412770==    at 0x484787F: free (vg_replace_malloc.c:989)
==3412770==    by 0x5FB2389: __snmp_xs_cb (SNMP.xs:1187)
==3412770==    by 0x56D0C0D: snmp_resend_request.constprop.0 (snmp_api.c:6815)
==3412770==    by 0x56D1A05: snmp_sess_timeout (snmp_api.c:6888)
==3412770==    by 0x56D1B47: snmp_timeout (snmp_api.c:6726)
==3412770==    by 0x5FB1418: XS_SNMP__main_loop (SNMP.xs:5067)
==3412770==    ...
==3412770==  Block was alloc'd at
==3412770==    at 0x4844818: malloc (vg_replace_malloc.c:446)
==3412770==    by 0x5FBD5FB: XS_SNMP__get (SNMP.xs:3335)
==3412770==    ...

==3412770== Invalid free() / delete / delete[] / realloc()
==3412770==    at 0x484787F: free (vg_replace_malloc.c:989)
==3412770==    by 0x5FB2389: __snmp_xs_cb (SNMP.xs:1187)
==3412770==    by 0x56D1986: snmp_sess_timeout (snmp_api.c:6881)
==3412770==    by 0x56D1B47: snmp_timeout (snmp_api.c:6726)
==3412770==    by 0x5FB1418: XS_SNMP__main_loop (SNMP.xs:5067)
==3412770==    ...
==3412770==  Address 0x6b8d720 is 0 bytes inside a block of size 16 free'd
==3412770==    [same free'd/alloc'd stacks as above]
```

This bug is resolved with commit cf5d7defd20 in the upstream repository.
Would it be possible to port this fix to the trixie-security suite?

A related bug with the bulkwalk method, got fixed in this PR:
https://github.com/net-snmp/net-snmp/pull/1166

Do you want me to file a separate bug report for this related bug?

-- System Information:
Debian Release: 13.7
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 7.2.11 (SMP w/40 CPU threads; PREEMPT)
Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8), LANGUAGE=en_NO:en_DK:en_US:en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libsnmp-perl depends on:
ii  libc6                       2.41-12+deb13u4
ii  libnetsnmptrapd40t64        5.9.4+dfsg-2+deb13u1
ii  libsnmp40t64                5.9.4+dfsg-2+deb13u1
ii  perl                        5.40.1-6+deb13u1
ii  perl-base [perlapi-5.40.1]  5.40.1-6+deb13u1

libsnmp-perl recommends no packages.

libsnmp-perl suggests no packages.

-- no debconf information
Technical Details
Message-ID: <NV6me-9sKp-9@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: Sebastian Bugge <sbugge@proton.me>
Newsgroups: linux.debian.bugs.dist
Subject: Bug#1152875: libsnmp-perl: use-after-free when an async request is retried
Date: Mon, 02 Nov 2026 21:00:02 +0100
Message-ID: <NV6me-9sKp-9@gated-at.bofh.it>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Mon Nov  2 19:51:10 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -1.65
Reply-To: Sebastian Bugge <sbugge@proton.me>, 1152875@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: csmall@debian.org
X-Debian-Pr-Message: report 1152875
X-Debian-Pr-Package: libsnmp-perl
X-Debian-Pr-Keywords: patch
X-Debian-Pr-Source: net-snmp
Authentication-Results: cassarossa.samfundet.no;
	iprev=pass (cirkus.samfundet.no) smtp.remote-ip=2001:67c:29f4::30
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Mailer: reportbug 13.2.0
X-Greylist: delayed 1520 seconds by postgrey-1.37 at buxtehude; Mon, 02 Nov 2026 19:50:30 UTC
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2000276
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 104
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Mon, 02 Nov 2026 20:25:01 +0100
X-Original-Message-ID: <179364750108.3241714.3632936358230033381.reportbug@cirkus.samfundet.no>