On Sun, Aug 04, 2019 at 10:20:24PM +1200, Richard Procter wrote:
> > On 2/08/2019, at 11:13 PM, Stefan Sperling <[email protected]> wrote:
> > @@ -4218,6 +4337,7 @@ iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ie
> >     uint8_t tid, type;
> >     int i, totlen, err, pad;
> >     int hdrlen2, rtsthres = ic->ic_rtsthreshold;
> > +   uint8_t *ivp;
> 
> nit: shift declare up under const struct iwm_rate? (declare order by size)

Sure, fixed in my tree.

> > +           tx->sec_ctl = IWM_TX_CMD_SEC_CCM;
> > +           memcpy(tx->key, k->k_key, k->k_len);
> 
> The ring warrants an explicit_bzero() on teardown to clear these keys
> I think. The other drivers don’t do this that I can see; perhaps 
> best left for another diff. 

Yes, this needs a systematic approach.

> > +           /* Fallback to software crypto for other ciphers. */
> > +                return (ieee80211_set_key(ic, ni, k));
> 
> nit: bad indent

Thanks for catching! Fixed in my tree.

> > +   }
> > +
> > +   cmd.key_flags = htole16(IWM_STA_KEY_FLG_CCM |
> > +       IWM_STA_KEY_FLG_WEP_KEY_MAP |
> > +       ((k->k_id << IWM_STA_KEY_FLG_KEYID_POS) &
> > +       IWM_STA_KEY_FLG_KEYID_MSK));
> > +   if (k->k_flags & IEEE80211_KEY_GROUP)
> > +           cmd.key_flags |= htole16(IWM_STA_KEY_MULTICAST);
> > +
> > +   memcpy(cmd.key, k->k_key, k->k_len);
> > +   cmd.key_offset = 0;
> > +   cmd.sta_id = IWM_STATION_ID;
> > +
> > +   return iwm_send_cmd_pdu(sc, IWM_ADD_STA_KEY, IWM_CMD_ASYNC,
> > +       sizeof(cmd), &cmd);
> 
> Might the async command open a race between loading keys and decrypting 
> received packets?

It can lead to all sorts of races but we have no other option because
net80211 runs lots of code in interrupt context. E.g. we might decide
to switch to a new SSID after a scan, which means we have to delete
the current key and perhaps set a new key. And all this happens in a
context where we're not allowed to sleep. So it has to be async, and
we don't bother checking for success/failure of the command. If this
command fails, the user will notice because net won't work. We could
of course check for a subsequent "key added" interrupt from the firmware
but what can we do when this fails? Reset the interface?

Regarding the small window between command initiation and success:
Encryption only affects unicast data frames, and we've already completed
a 4-way handshake with the peer which means newly arriving data frames will
be encrypted. Management frames will still pass. I guess the worst that
might happen is that some data frames sent before the key was installed
might be retransmitted because the firmware would fail to decrypt them.

FWIW, iwn(4) has had the same problem forever and I don't see anyone
complaining.

> > #define IWM_UCODE_TLV_API_BITS \
> > -   
> > "\020\10FRAGMENTED_SCAN\11WIFI_MCC_UPDATE\16WIDE_CMD_HDR\22LQ_SS_PARAMS\30EXT_SCAN_PRIO\33TX_POWER_CHAIN"
> > +   
> > "\020\10FRAGMENTED_SCAN\11WIFI_MCC_UPDATE\16WIDE_CMD_HDR\22LQ_SS_PARAMS\30EXT_SCAN_PRIO\33TX_POWER_CHAIN\35TKIP_MIC_KEYS"
> > 
> > /**
> >  * uCode capabilities
> 
> note: I copied this last hunk over from the linux driver; it’s unused by your 
> diff. 
> 

I think it's good to keep this because such definitions are the only
form of "hardware docs" we can get...

Reply via email to