From: Karsten Graul kgraul@linux.ibm.com
mainline inclusion from mainline-v5.16-rc3 commit 587acad41f1bc48e16f42bb2aca63bf323380be8 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9S242 CVE: CVE-2021-47559
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
Coverity reports a possible NULL dereferencing problem:
in smc_vlan_by_tcpsk(): 6. returned_null: netdev_lower_get_next returns NULL (checked 29 out of 30 times). 7. var_assigned: Assigning: ndev = NULL return value from netdev_lower_get_next. 1623 ndev = (struct net_device *)netdev_lower_get_next(ndev, &lower); CID 1468509 (#1 of 1): Dereference null return value (NULL_RETURNS) 8. dereference: Dereferencing a pointer that might be NULL ndev when calling is_vlan_dev. 1624 if (is_vlan_dev(ndev)) {
Remove the manual implementation and use netdev_walk_all_lower_dev() to iterate over the lower devices. While on it remove an obsolete function parameter comment.
Fixes: cb9d43f67754 ("net/smc: determine vlan_id of stacked net_device") Suggested-by: Julian Wiedmann jwi@linux.ibm.com Signed-off-by: Karsten Graul kgraul@linux.ibm.com Signed-off-by: Jakub Kicinski kuba@kernel.org
Conflicts: net/smc/smc_core.c [The conflict occurs because the commit eff7423365a6("net: core: introduce struct netdev_nested_priv for nested interface infrastructure") and bc36d2fc93eb("net/smc: consolidate function parameters") are not merged] Signed-off-by: Zhengchao Shao shaozhengchao@huawei.com --- net/smc/smc_core.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 2c9baf8bf118..4b928e8fc699 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -512,14 +512,24 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid) } }
-/* Determine vlan of internal TCP socket. - * @vlan_id: address to store the determined vlan id into - */ +static int smc_vlan_by_tcpsk_walk(struct net_device *lower_dev, void *data) +{ + unsigned short *vlan_id = (unsigned short *)data; + + if (is_vlan_dev(lower_dev)) { + *vlan_id = vlan_dev_vlan_id(lower_dev); + return 1; + } + + return 0; +} + +/* Determine vlan of internal TCP socket. */ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id) { struct dst_entry *dst = sk_dst_get(clcsock->sk); struct net_device *ndev; - int i, nest_lvl, rc = 0; + int rc = 0;
*vlan_id = 0; if (!dst) { @@ -538,19 +548,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id) }
rtnl_lock(); - nest_lvl = dev_get_nest_level(ndev); - for (i = 0; i < nest_lvl; i++) { - struct list_head *lower = &ndev->adj_list.lower; - - if (list_empty(lower)) - break; - lower = lower->next; - ndev = (struct net_device *)netdev_lower_get_next(ndev, &lower); - if (is_vlan_dev(ndev)) { - *vlan_id = vlan_dev_vlan_id(ndev); - break; - } - } + netdev_walk_all_lower_dev(ndev, smc_vlan_by_tcpsk_walk, (void *)vlan_id); rtnl_unlock();
out_rel:
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/8209 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/4...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/8209 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/4...