Re: [PATCH net v3] net: dsa: Check existence of .port_mdb_add callback before calling it

From: David Miller
Date: Mon Aug 12 2019 - 00:37:43 EST


From: Chen-Yu Tsai <wens@xxxxxxxxxx>
Date: Sun, 11 Aug 2019 22:18:25 +0800

> From: Chen-Yu Tsai <wens@xxxxxxxx>
>
> The dsa framework has optional .port_mdb_{prepare,add,del} callback fields
> for drivers to handle multicast database entries. When adding an entry, the
> framework goes through a prepare phase, then a commit phase. Drivers not
> providing these callbacks should be detected in the prepare phase.
>
> DSA core may still bypass the bridge layer and call the dsa_port_mdb_add
> function directly with no prepare phase or no switchdev trans object,
> and the framework ends up calling an undefined .port_mdb_add callback.
> This results in a NULL pointer dereference, as shown in the log below.
>
> The other functions seem to be properly guarded. Do the same for
> .port_mdb_add in dsa_switch_mdb_add_bitmap() as well.
...
> Fixes: e6db98db8a95 ("net: dsa: add switch mdb bitmap functions")
> Signed-off-by: Chen-Yu Tsai <wens@xxxxxxxx>

Applied and queued up for -stable, thanks.