From patchwork Thu Aug 20 22:49:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 1348662 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=lPOA4W6d; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BXfy62DQbz9sPf for ; Fri, 21 Aug 2020 08:50:54 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CC40F86C56; Thu, 20 Aug 2020 22:50:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oCizpK7rRqLL; Thu, 20 Aug 2020 22:50:50 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id DBF6786C5E; Thu, 20 Aug 2020 22:50:49 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A5407C08A5; Thu, 20 Aug 2020 22:50:49 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0E10AC0895 for ; Thu, 20 Aug 2020 22:50:48 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D4B7423B28 for ; Thu, 20 Aug 2020 22:50:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bSL7tOS0-sWO for ; Thu, 20 Aug 2020 22:50:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by silver.osuosl.org (Postfix) with ESMTPS id 5C23522D0D for ; Thu, 20 Aug 2020 22:50:15 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id bh1so1593725plb.12 for ; Thu, 20 Aug 2020 15:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xW/vElZ+ZWMe+TBtkj+RmB9V1EnWNWbR6UuIfoH1UOo=; b=lPOA4W6dn0gJYysJIySQ+BVGKhWLFjCbj+LhDG9Q5vqqD5RBBWgO+DhoSeU9nQIRmB WDMM2pvOclXchw6fXNGt93yCgPA89fAgR7TzuYj2QhRkMCBBE/c1hvUrc95c+yuAMTjr a5SEANwEe1muf+5DnFoOD9SRywb4HMkvuWTPiXDkHbYudE7n9/bX8p8/ztCfzo7uMLWJ Ke4dM7/yT/Y8RXF65D5QSXtF89gnzrLuEbxMsv1CPCEJT7uOmsaI9zaTtL1MwS/FIFxr Qs2cHa1h/JOP6Me7ZH/4y57WYTOxx3pX09isEnCOF2yXbX6GI0gpidyf+it64BD4o8+o Ab5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xW/vElZ+ZWMe+TBtkj+RmB9V1EnWNWbR6UuIfoH1UOo=; b=oKPQsucoy46+MMhA08DukWHXuyXS5tPOZvJzGTQGUrjxgS2ixSr3D4Puu3ybA4iW1d XhHQVAbzhwQUFLMEAF7w+iIJkp22GebTvBaeIK1q/hxEaXtR/rdh1MeAcxZO/vus1Q3h nEU1XnGfasYFMzNygAAGVCEukYePqVZsalALhHC7+L9nX1cP9y5ErDlKmjmB+/9sBi3m FmhHtWp2CECMKrTU+PtM9CbzU1fE3ONlREW1W9PNBVtLL4uKDMDHLExRmKa68qtNWaSm T4lxr85vdPas5KtCkBvBaClatvkUgCK8nr1EWISdSVjdutmXVbJZsVuXlxAj3SmrLdc6 Aogg== X-Gm-Message-State: AOAM531ajw9Zrxb/MpzTcwZSU+sz2087w7AHiHRa1Zqrx6AQHwWvTnx9 MPoWQjnWfTxnV7Z6m0YqMzx5bqO02ZP95w== X-Google-Smtp-Source: ABdhPJyc7PylZ8m2ljtACpss1EX0UeOknpBpHuL9ZxaY9QDphTKfv1OknMEk6dCuBG5QC8JJPZzyGQ== X-Received: by 2002:a17:90a:39c8:: with SMTP id k8mr12203pjf.19.1597963814420; Thu, 20 Aug 2020 15:50:14 -0700 (PDT) Received: from gizo.domain (97-115-99-106.ptld.qwest.net. [97.115.99.106]) by smtp.gmail.com with ESMTPSA id y6sm116866pfr.61.2020.08.20.15.50.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2020 15:50:12 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org Date: Thu, 20 Aug 2020 15:49:34 -0700 Message-Id: <1597963790-12362-8-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597963790-12362-1-git-send-email-gvrose8192@gmail.com> References: <1597963790-12362-1-git-send-email-gvrose8192@gmail.com> Cc: Guillaume Nault Subject: [ovs-dev] [PATCH 07/23] datapath: fix GFP flags in rtnl_net_notifyid() X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Guillaume Nault Upstream commit: commit d4e4fdf9e4a27c87edb79b1478955075be141f67 Author: Guillaume Nault Date: Wed Oct 23 18:39:04 2019 +0200 netns: fix GFP flags in rtnl_net_notifyid() In rtnl_net_notifyid(), we certainly can't pass a null GFP flag to rtnl_notify(). A GFP_KERNEL flag would be fine in most circumstances, but there are a few paths calling rtnl_net_notifyid() from atomic context or from RCU critical sections. The later also precludes the use of gfp_any() as it wouldn't detect the RCU case. Also, the nlmsg_new() call is wrong too, as it uses GFP_KERNEL unconditionally. Therefore, we need to pass the GFP flags as parameter and propagate it through function calls until the proper flags can be determined. In most cases, GFP_KERNEL is fine. The exceptions are: * openvswitch: ovs_vport_cmd_get() and ovs_vport_cmd_dump() indirectly call rtnl_net_notifyid() from RCU critical section, * rtnetlink: rtmsg_ifinfo_build_skb() already receives GFP flags as parameter. Also, in ovs_vport_cmd_build_info(), let's change the GFP flags used by nlmsg_new(). The function is allowed to sleep, so better make the flags consistent with the ones used in the following ovs_vport_cmd_fill_info() call. Found by code inspection. Fixes: 9a9634545c70 ("netns: notify netns id events") Signed-off-by: Guillaume Nault Acked-by: Nicolas Dichtel Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Backport the datapath.c portion of this fix. Cc: Guillaume Nault Signed-off-by: Greg Rose --- datapath/datapath.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/datapath/datapath.c b/datapath/datapath.c index 36f1e78..1235c4e 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1990,7 +1990,7 @@ static struct genl_family dp_datapath_genl_family __ro_after_init = { /* Called with ovs_mutex or RCU read lock. */ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, struct net *net, u32 portid, u32 seq, - u32 flags, u8 cmd) + u32 flags, u8 cmd, gfp_t gfp) { struct ovs_header *ovs_header; struct ovs_vport_stats vport_stats; @@ -2012,7 +2012,7 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, #ifdef HAVE_PEERNET2ID_ALLOC if (!net_eq(net, dev_net(vport->dev))) { - int id = peernet2id_alloc(net, dev_net(vport->dev)); + int id = peernet2id_alloc(net, dev_net(vport->dev), gfp); if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id)) goto nla_put_failure; @@ -2054,11 +2054,12 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net, struct sk_buff *skb; int retval; - skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!skb) return ERR_PTR(-ENOMEM); - retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd); + retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd, + GFP_KERNEL); BUG_ON(retval < 0); return skb; @@ -2200,7 +2201,7 @@ restart: err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, - OVS_VPORT_CMD_NEW); + OVS_VPORT_CMD_NEW, GFP_KERNEL); BUG_ON(err < 0); new_headroom = netdev_get_fwd_headroom(vport->dev); @@ -2260,7 +2261,7 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, - OVS_VPORT_CMD_SET); + OVS_VPORT_CMD_SET, GFP_KERNEL); BUG_ON(err < 0); ovs_unlock(); @@ -2300,7 +2301,7 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, - OVS_VPORT_CMD_DEL); + OVS_VPORT_CMD_DEL, GFP_KERNEL); BUG_ON(err < 0); /* the vport deletion may trigger dp headroom update */ @@ -2347,7 +2348,7 @@ static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info) goto exit_unlock_free; err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, - OVS_VPORT_CMD_GET); + OVS_VPORT_CMD_GET, GFP_ATOMIC); BUG_ON(err < 0); rcu_read_unlock(); @@ -2383,7 +2384,8 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI, - OVS_VPORT_CMD_GET) < 0) + OVS_VPORT_CMD_GET, + GFP_ATOMIC) < 0) goto out; j++;