sonic-net / sonic-net/sonic-sairedis

[Bug] Incorrect size limitation for string attribute in meta_generic_validation_create

Open
#1,663 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
85
Forks
425
Avg merge
4d 21h
Merged PRs (30d)
16

Description

I want to create a new SAI object with MANDATORY_ON_CREATE char type attribute in SWSS. But when I set the attribute value to 'OCM0-0|0|191262500' and call SAI create function, it will be failed with error "SAI_ATTR_VALUE_TYPE_CHARDATA host interface name is too long".

I checked sairedis meta.cpp code, found the string size check is incorrect. It always uses the SAI_HOSTIF_NAME_SIZE (16) for all string attributes. This part of code is shown below:

sai_status_t Meta::meta_generic_validation_create(...)
{
...
        switch (md.attrvaluetype)
        {
            case SAI_ATTR_VALUE_TYPE_CHARDATA:

                {
                    const char* chardata = value.chardata;

                    size_t len = strnlen(chardata, SAI_HOSTIF_NAME_SIZE);

                    if (len == SAI_HOSTIF_NAME_SIZE)
                    {
                        META_LOG_ERROR(md, "host interface name is too long");

                        return SAI_STATUS_INVALID_PARAMETER;
                    }

...
}

I think this size check should only apply to host interface name and genetlink multicast group name but not for all string attributes, as SAI defined the maximum name size in saihostif.h, but others are not which should be in the range of chardata[32]. Please see the below definition code from SAI:

/**
 * @brief Defines maximum host interface name
 */
#define SAI_HOSTIF_NAME_SIZE 16

/**
 * @brief Defines maximum length of generic netlink multicast group name
 */
#define SAI_HOSTIF_GENETLINK_MCGRP_NAME_SIZE 16
typedef union _sai_attribute_value_t
{
    /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_BOOL */
    bool booldata;

    /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_CHARDATA */
    char chardata[32];

    /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_UINT8 */
    sai_uint8_t u8;

My error log is shown as follows:

2025 Oct  9 20:57:30.033605 sonic NOTICE swss#orchagent: :- translateObjectAttr: translateObjectAttr, field = name, value = OCM0-0|0|191262500
2025 Oct  9 20:57:30.033605 sonic NOTICE swss#orchagent: :- translateObjectAttr: translateObjectAttr, field = upper_frequency, value = 191337500
2025 Oct  9 20:57:30.033605 sonic ERR swss#orchagent: :- meta_generic_validation_create: SAI_OTN_OCM_CHANNEL_ATTR_NAME:SAI_ATTR_VALUE_TYPE_CHARDATA host interface name is too long
2025 Oct  9 20:57:30.033605 sonic ERR swss#orchagent: :- createObject: Failed to create SAI_OBJECT_TYPE_OTN_OCM_CHANNEL|OCM0-0|0|191262500, rv=-5
2025 Oct  9 20:57:30.033605 sonic ERR swss#orchagent: :- doTask: Failed to create object
2025 Oct  9 20:57:30.035943 sonic INFO swss#supervisord: message repeated 12 times: [ orchagent ]
2025 Oct  9 20:57:30.035943 sonic INFO swss#supervisord: orchagent terminate called after throwing an instance of 'std::runtime_error'
2025 Oct  9 20:57:30.035943 sonic INFO swss#supervisord: orchagent   what():  :- doTask: Failed to create object
2025 Oct  9 20:57:30.363750 sonic INFO swss#supervisord 2025-10-09 20:57:30,363 WARN exited: orchagent (terminated by SIGABRT (core dumped); not expected)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in sairedis meta.cpp at Meta::meta_generic_validation_create and inspect the SAI_ATTR_VALUE_TYPE_CHARDATA validation shown in the issue. Compare the host-interface and genetlink name definitions with the generic chardata capacity, then reproduce the OTN OCM channel value from the report. Done means generic string attributes are not rejected by the host-interface limit while the named interface limits remain enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.