Package: Ledmon
Version: 0.95-2 & 0.97-1.1
Tags: patch

I have identified a memory leak in the ledmon package on servers with
the AMD SATA controller. In version 0.95 of ledmon, the amd_em_enabled
function in the amd.c file contains a pointer variable that is not
freed, leading to a significant memory leak. In version 0.97, there is
an additional memory leak in the vmdssd_check_slot_module function in
the vmdssd.c file along with the leak mentioned above, where another
pointer variable is not freed.

Here is a transcript:

/sbin/ledmon --foreground
pmap -p <ledmon pid> | grep -i total
anonymous memory: 132K
ps -eo pid,rss,comm | grep -i <ledmon pid>
<ledmon pid>  2252 ledmon

after a few minutes

pmap -p <ledmon pid> | grep -i total
anonymous memory: 232K
ps -eo pid,rss,comm | grep -i <ledmon pid>
<ledmon pid>  2656 ledmon

Here, we can identify a significant memory leak in the ledmon binary,
as it grows over time when the program runs for a few minutes.

Fix :
./src/amd.c:113
int amd_em_enabled(const char *path)
{
        char *platform;
        int rc;

        /* Default to SGPIO interface */
        amd_interface = AMD_INTF_SGPIO;

        platform = get_text("/sys/class/dmi/id", "product_name");
        if (!platform)
                return 0;

        /* Check IPMI platforms */
        if (!strncmp(platform, "ETHANOL_X", 9)) {
                amd_interface = AMD_INTF_IPMI;
                amd_ipmi_platform = AMD_PLATFORM_ETHANOL_X;
        } else if (!strncmp(platform, "DAYTONA_X", 9)) {
                amd_interface = AMD_INTF_IPMI;
                amd_ipmi_platform = AMD_PLATFORM_DAYTONA_X;
        }

        switch (amd_interface) {
        case AMD_INTF_SGPIO:
                rc = _amd_sgpio_em_enabled(path);
                break;
        case AMD_INTF_IPMI:
                rc = _amd_ipmi_em_enabled(path);
                break;
        default:
                log_error("Unknown interface for AMD %s platform\n",
                          platform);
                rc = -EOPNOTSUPP;
                break;
        }
+      free(platform);  // Free the allocated memory for platform
pointer variable
        return rc;
}

/src/vmdssd.c:93

bool vmdssd_check_slot_module(const char *slot_path)
{
    char *address;
    struct cntrl_device *cntrl;

    address = get_text(slot_path, "address");
    if (address == NULL)
        return false;

    // Check if slot address contains vmd domain
    list_for_each(sysfs_get_cntrl_devices(), cntrl) {
        if (cntrl->cntrl_type == CNTRL_TYPE_VMD) {
            if (cntrl->domain == NULL)
                continue;
            if (strstr(address, cntrl->domain) == NULL)
                continue;
+           free(address);  // Free memory before returning true
            return true;
        }
    }

+   free(address);  // Ensure memory is freed before returning false
    return false;
}

I suggest that the proposed fix be implemented to address the memory
leak in servers with the AMD SATA controller. For reference, here is
the acknowledgment from the upstream developer:
https://github.com/intel/ledmon/issues/84#issuecomment-2391056141

I am using Debian GNU/Linux 11 (bullseye), kernel 5.10.191 and libc6 2.31-13.

Reply via email to