nvethernet:split macsec_sa_state_lut 2 sysfs nodes

Issue: Observed KSAN bug when using both Tx and Rx sa_state luts in a
single sysfs Entry as the data is not within the PAGE_SIZE

Fix: Split the sa_state_lut to 2 entries different for Tx and Rx

Bug 5178711

Change-Id: Id6929abae263622b02c00cef459e974661b5f1bc
Signed-off-by: Sanath Kumar Gampa <sgampa@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3334987
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Tested-by: Nan Zhang <nazhang@nvidia.com>
Reviewed-by: Srinivas Ramachandran <srinivasra@nvidia.com>
Reviewed-by: Mahesh Patil <maheshp@nvidia.com>
This commit is contained in:
Sanath Kumar Gampa
2025-04-07 11:59:27 +00:00
committed by Jon Hunter
parent 41bf84e591
commit efd43d9c76

View File

@@ -2306,7 +2306,7 @@ static void dump_sa_state_lut(char **buf_p, unsigned short ctlr_sel,
if ((lut_config.flags & OSI_LUT_FLAGS_ENTRY_VALID) ==
OSI_LUT_FLAGS_ENTRY_VALID) {
buf += scnprintf(buf, PAGE_SIZE,
"%d.\tnext_pn: %u\n", i,
"%d.\tnpn: %u\n", i,
lut_config.sa_state_out.next_pn);
} else {
buf += scnprintf(buf, PAGE_SIZE,
@@ -2315,7 +2315,7 @@ static void dump_sa_state_lut(char **buf_p, unsigned short ctlr_sel,
break;
case OSI_CTLR_SEL_RX:
buf += scnprintf(buf, PAGE_SIZE,
"%d.\tnext_pn: %u lowest_pn: %u\n", i,
"%d.\tnpn: %u lpn: %u\n", i,
lut_config.sa_state_out.next_pn,
lut_config.sa_state_out.lowest_pn);
break;
@@ -2329,15 +2329,15 @@ exit:
}
/**
* @brief Shows the current SA state LUT configuration
* @brief Shows the TX current SA state LUT configuration
*
* @param[in] dev: Device data.
* @param[in] attr: Device attribute
* @param[in] buf: Buffer to print the current LUT configuration
*/
static ssize_t macsec_sa_state_lut_show(struct device *dev,
struct device_attribute *attr,
char *buf)
static ssize_t macsec_sa_state_lut_tx_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct net_device *ndev = (struct net_device *)dev_get_drvdata(dev);
struct ether_priv_data *pdata = netdev_priv(ndev);
@@ -2352,12 +2352,44 @@ static ssize_t macsec_sa_state_lut_show(struct device *dev,
buf += scnprintf(buf, PAGE_SIZE, "Tx:\n");
dump_sa_state_lut(&buf, OSI_CTLR_SEL_TX, osi_core);
return (buf - start);
}
static DEVICE_ATTR(macsec_sa_state_lut_tx, (S_IRUGO | S_IWUSR),
macsec_sa_state_lut_tx_show,
NULL);
/**
* @brief Shows the RX current SA state LUT configuration
*
* @param[in] dev: Device data.
* @param[in] attr: Device attribute
* @param[in] buf: Buffer to print the current LUT configuration
*/
static ssize_t macsec_sa_state_lut_rx_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct net_device *ndev = (struct net_device *)dev_get_drvdata(dev);
struct ether_priv_data *pdata = netdev_priv(ndev);
struct osi_core_priv_data *osi_core = pdata->osi_core;
char *start = buf;
if (!netif_running(ndev)) {
dev_err(pdata->dev, "Not Allowed. Ether interface is not up\n");
return 0;
}
buf += scnprintf(buf, PAGE_SIZE, "Rx:\n");
dump_sa_state_lut(&buf, OSI_CTLR_SEL_RX, osi_core);
return (buf - start);
}
static DEVICE_ATTR(macsec_sa_state_lut_rx, (S_IRUGO | S_IWUSR),
macsec_sa_state_lut_rx_show,
NULL);
/**
* @brief Set the SA state LUT configuration
*
@@ -2425,7 +2457,7 @@ exit:
*
*/
static DEVICE_ATTR(macsec_sa_state_lut, (S_IRUGO | S_IWUSR),
macsec_sa_state_lut_show,
NULL,
macsec_sa_state_lut_store);
@@ -3489,6 +3521,8 @@ static struct attribute *ether_sysfs_attrs[] = {
#endif /* MACSEC_KEY_PROGRAM */
&dev_attr_macsec_sc_state_lut.attr,
&dev_attr_macsec_sa_state_lut.attr,
&dev_attr_macsec_sa_state_lut_tx.attr,
&dev_attr_macsec_sa_state_lut_rx.attr,
&dev_attr_macsec_sc_param_lut.attr,
&dev_attr_macsec_sc_param_tx_lut.attr,
&dev_attr_macsec_sc_param_tx_lut_2.attr,