public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine.com>
To: carlos.fernandez@technica-engineering.de
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: macsec SCI assignment for ES = 0
Date: Thu, 15 Jun 2023 16:23:55 +0200	[thread overview]
Message-ID: <ZIse+5VepvY5dXN0@corigine.com> (raw)
In-Reply-To: <20230615111315.6072-1-carlos.fernandez@technica-engineering.de>

On Thu, Jun 15, 2023 at 01:13:15PM +0200, carlos.fernandez@technica-engineering.de wrote:
> From: Carlos Fernandez <carlos.fernandez@technica-engineering.de>
> 
> According to 802.1AE standard, when ES and SC flags in TCI are zero, used
> SCI should be the current active SC_RX. Current kernel does not implement
> it and uses the header MAC address.
> 
> Without this patch, when ES = 0 (using a bridge or switch), header MAC
> will not fit the SCI and MACSec frames will be discarted.
> 
> Signed-off-by: Carlos Fernandez <carlos.fernandez@technica-engineering.de>

Hi Carlos,

some feedback from my side.

> ---
>  drivers/net/macsec.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
> index 3427993f94f7..ea9b15d555f4 100644
> --- a/drivers/net/macsec.c
> +++ b/drivers/net/macsec.c
> @@ -256,16 +256,32 @@ static sci_t make_sci(const u8 *addr, __be16 port)
>  	return sci;
>  }
>  
> -static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
> +static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
> +		struct macsec_rxh_data *rxd)

The indentation of the line above should be such that it aligns with the
inside of the parentheses on the previous line.

static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
			      struct macsec_rxh_data *rxd)

>  {
> +	struct macsec_dev *macsec_device;
>  	sci_t sci;
> -
> +	/* SC = 1*/
>  	if (sci_present)
>  		memcpy(&sci, hdr->secure_channel_id,
> -		       sizeof(hdr->secure_channel_id));
> -	else
> +				sizeof(hdr->secure_channel_id));
> +	/* SC = 0; ES = 0*/
> +	else if (0 == (hdr->tci_an & (MACSEC_TCI_ES | MACSEC_TCI_SC))) {
> +		list_for_each_entry_rcu(macsec_device, &rxd->secys, secys) {
> +			struct macsec_rx_sc *rx_sc;
> +			struct macsec_secy *secy = &macsec_device->secy;

For new networking code, please use reverse xmas tree order - longest line
to shortest - for local variable declarations.

			struct macsec_secy *secy = &macsec_device->secy;
			struct macsec_rx_sc *rx_sc;

> +
> +			for_each_rxsc(secy, rx_sc) {
> +				rx_sc = rx_sc ? macsec_rxsc_get(rx_sc) : NULL;
> +				if (rx_sc && rx_sc->active) {
> +					sci = rx_sc->sci;
> +					return sci;
> +				}

I wonder if this can be more succinctly written as:

				if (rx_sc && rx_sc->active)
					return rx_sc->sci;

> +			}
> +		}
> +	} else {
>  		sci = make_sci(hdr->eth.h_source, MACSEC_PORT_ES);
> -
> +	}
>  	return sci;
>  }

clang-16 complains, as I understand things, that if
the else if condition is met above, but sci is not returned from
within it, then sci is uninitialised here.

Perhaps that cannot happen.
But perhaps it would be better guard against it somehow?

 drivers/net/macsec.c:270:3: warning: variable 'sci' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
                 list_for_each_entry_rcu(macsec_device, &rxd->secys, secys) {
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ./include/linux/rculist.h:392:3: note: expanded from macro 'list_for_each_entry_rcu'
                 &pos->member != (head);                                 \
                 ^~~~~~~~~~~~~~~~~~~~~~
 drivers/net/macsec.c:285:9: note: uninitialized use occurs here
         return sci;
                ^~~
 drivers/net/macsec.c:270:3: note: remove the condition if it is always true
                 list_for_each_entry_rcu(macsec_device, &rxd->secys, secys) {
                 ^
 ./include/linux/rculist.h:392:3: note: expanded from macro 'list_for_each_entry_rcu'
                 &pos->member != (head);                                 \
                 ^
 drivers/net/macsec.c:263:11: note: initialize the variable 'sci' to silence this warning
         sci_t sci;
                  ^
                   = 0

...

  reply	other threads:[~2023-06-15 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 11:13 [PATCH] net: macsec SCI assignment for ES = 0 carlos.fernandez
2023-06-15 14:23 ` Simon Horman [this message]
2023-06-15 14:58   ` Carlos Fernandez
2023-06-15 17:52 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZIse+5VepvY5dXN0@corigine.com \
    --to=simon.horman@corigine.com \
    --cc=carlos.fernandez@technica-engineering.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox