librenms / librenms

Community-based GPL-licensed network monitoring system
https://www.librenms.org
Other
3.94k stars 2.31k forks source link

DOS/recursive loop with faulty/0 table index #16740

Open dirkx opened 2 days ago

dirkx commented 2 days ago

The problem

Sometimes tables respond with a 0 on the entry of the table itself; e.g. for the entity MIB - on .1.3.6.1.2.1.47.1.1.1.1.0. I am not an SNMP expert - but am guessing this is wrong.

However that results in an NULL/extra table entry that causes recursion in the function printEntPhysical($device, $ent, $level, $class) - and then an out of memory.

Perhaps the

    $count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE device_id = '" . $device['device_id'] . "' AND entPhysicalContainedIn = '" . $ent['entPhysicalIndex'] . "'");

Needs some sort of cyclic/non null protection. E.g by keeping a entPhysicalIndex visited table (as only strict hierachies are allowed).

SNMP walk that causes the crash:

NTITY-MIB::entPhysicalTable.0 = INTEGER: 0
ENTITY-MIB::entPhysicalIndex.1 = INTEGER: 1
ENTITY-MIB::entPhysicalDescr.1.0 = STRING: Valve controller
ENTITY-MIB::entPhysicalClass.1.0 = INTEGER: other(1)
ENTITY-MIB::entPhysicalName.1.0 = STRING: XXX
etc

One that is fine:

ENTITY-MIB::entPhysicalIndex.1 = INTEGER: 1
ENTITY-MIB::entPhysicalDescr.1.0 = STRING: Valve controller
ENTITY-MIB::entPhysicalClass.1.0 = INTEGER: other(1)
ENTITY-MIB::entPhysicalName.1.0 = STRING: XXXX
etc

Database result after a discovery that causes the crash:

+----------------+-----------+------------------+------------------+------------------+-----------------+----------------------------+------------------------+------------------------+------------------+--------------------+------------------+----------------------+-----------------------+------------------------+------------------------+-------------------------+---------------------------------------------------------+---------+ | entPhysical_id | device_id | entPhysicalIndex | entPhysicalDescr | entPhysicalClass | entPhysicalName | entPhysicalHardwareRev | entPhysicalFirmwareRev | entPhysicalSoftwareRev | entPhysicalAlias | entPhysicalAssetID | entPhysicalIsFRU | entPhysicalModelName | entPhysicalVendorType | entPhysicalSerialNum | entPhysicalContainedIn | entPhysicalParentRelPos | entPhysicalMfgName | ifIndex | +----------------+-----------+------------------+------------------+------------------+-----------------+----------------------------+------------------------+------------------------+------------------+--------------------+------------------+----------------------+-----------------------+------------------------+------------------------+-------------------------+---------------------------------------------------------+---------+ | 1797 | 933 | 0 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 0 | -1 | NULL | NULL | | 1798 | 933 | 1 | Valve controller | other | XXXX | XXX| 1.1.5 | XXX| NULL | NULL | NULL | XXXX | NULL | XXXXX | 1 | -1 | XXXX | NULL | +----------------+-----------+------------------+------------------+------------------+-----------------+----------------------------+------------------------+------------------------+------------------+--------------------+------------------+----------------------+-----------------------+------------------------+------------------------+-------------------------+---------------------------------------------------------+---------+

Output of ./validate.php

===========================================
Component | Version
--------- | -------
LibreNMS  | 24.9.0 (2024-09-30T01:40:22+02:00)
DB Schema | 2024_08_27_182000_ports_statistics_table_rev_length (300)
PHP       | XX
Python    | XX
Database  | MySQL XX
RRDTool   | XX
SNMP      | 5.9.4.pre2
===========================================

[OK]    Installed from package; no Composer required
[OK]    Database connection successful
[OK]    Database connection successful
[OK]    Database Schema is current
[OK]    SQL Server meets minimum requirements
[OK]    lower_case_table_names is enabled
[OK]    MySQL engine is optimal
[OK]    Database and column collations are correct
[OK]    Database schema correct
[OK]    MySQL and PHP time match
[OK]    Active pollers found
[OK]    Dispatcher Service is enabled
[OK]    Locks are functional
[OK]    No active python wrapper pollers found
[OK]    Redis is unavailable
[OK]    rrdtool version ok
[OK]    Connected to rrdcached

What was the last working version of LibreNMS?

No response

Anything in the logs that might be useful for us?

No response