From patchwork Thu Sep 27 17:58:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 975843 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=brauner.io Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=brauner.io header.i=@brauner.io header.b="CyEIEhW3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42LjJJ1jFlz9s1x for ; Fri, 28 Sep 2018 04:00:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728651AbeI1ATI (ORCPT ); Thu, 27 Sep 2018 20:19:08 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34585 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeI1ATG (ORCPT ); Thu, 27 Sep 2018 20:19:06 -0400 Received: by mail-ed1-f65.google.com with SMTP id q19-v6so5888320edr.1 for ; Thu, 27 Sep 2018 10:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YmXqigRf7MfAJWZebhXsQvKzthN4owk6/gKa5Zoooq0=; b=CyEIEhW3dT+9ySGJeYFgzZtQ5alkC47y8dUzfcXK8YkWal3m10U3JQVmSMzVNBmg+A zFiOhPRUkQZWc+PZcc2gWJm1f9Jh8Npa5ffqtt5SVrhcy65GXEaFZyq2dKYcoa51HXLu uAyPyIWrSUamLgSolJtHjrKWHTFXhALFCLfuB8cpjYpMKDEohBTY7xVpiinWib9z+3GC 4+S53gXtw3pepZEn3Zkr9OPczKxtUwH3XfuIHRnAV53sT/BnkcZ8YqGWFdYWswsOTOaI WRh4UFM6GkRbJlcg423TaNnHaHE4rqcsbGviczbWFKe9X/IwN6Xy4LJ+tLgL0QNCcEdb d9hg== 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=YmXqigRf7MfAJWZebhXsQvKzthN4owk6/gKa5Zoooq0=; b=CJaoBu5aMqsipmlhWOKpJKO9OYCrMV/JdXTLfkltPb4QgqJddn9HAoFXxl/LPjZDhy kKEyUlejMfAU+4Jun4exP/EIPqBF9gqzJ4mgGS518w2zj66AGonB3VGu0QKO2F3qyWLu d4xUI/Vdr4IayTfC9mqL+og3iMDrHTENN5ZdQPF1VoxbJETCIOZzgoZr6liNmjDw2O2M x/OpygJpgxjuVHkMlI4OJ4Ux0l4Qux/Pf9MVnglnT8W4zVG/CU8WAI2fk6XW54qBvhC9 S1daDQ8+wma+e5x+b8HhO9vDXO66YnYJs+gHeDGf5LCBNGcrULO3MPGf6UrUKHObORlA CzGw== X-Gm-Message-State: ABuFfoisfrSHzsB0T09Wz2pEvKsFdrWaoYCz2ihTmwjOZQAs9gSVi+eA L+B9gFYx4er4NtRW7X3n045UaQ== X-Google-Smtp-Source: ACcGV62gr2+Olm8NzrDZqC07NtlAPorXCWBmiGr/u3JnM1ybFnPfARmz+f2bSG/dGYVP7f7fI2CrsA== X-Received: by 2002:a17:906:619a:: with SMTP id q26-v6mr2888167ejk.127.1538071178879; Thu, 27 Sep 2018 10:59:38 -0700 (PDT) Received: from localhost.localdomain (fa-padur-binz.ediscom.de. [212.204.40.18]) by smtp.gmail.com with ESMTPSA id a9-v6sm1532606edi.26.2018.09.27.10.59.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 10:59:37 -0700 (PDT) From: Christian Brauner To: jbenc@redhat.com, davem@davemloft.net, dsahern@gmail.com, stephen@networkplumber.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Brauner Subject: [PATCH net-next 5/7] phonet: add RTM_GETADDR2 Date: Thu, 27 Sep 2018 19:58:55 +0200 Message-Id: <20180927175857.3511-6-christian@brauner.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180927175857.3511-1-christian@brauner.io> References: <20180927175857.3511-1-christian@brauner.io> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Various userspace programs (e.g. iproute2) have sent RTM_GETADDR requests with struct ifinfomsg. This is wrong and should have been struct ifaddrmsg all along as mandated by the manpages. However, dump requests so far didn't parse the netlink message that was sent and succeeded even when a wrong struct was passed along. Currently, the message is parsed under the assumption that the correct struct ifaddrmsg is sent down. If the parsing fails the kernel will still fulfill the request to preserve backwards compatability but a rate-limited message that there were leftover bytes after parsing the message is recorded in dmesg. It has been argued that this is unacceptable [1]. But various new features that got and will get added to RTM_GETADDR make it necessary to definitely know what header was passed along. This is currently not possible without resorting to (likely unreliable) hacks such as introducing a nested attribute that ensures that RTM_GETADDR which pass along properties such as IFA_TARGET_NETNSID always exceed RTM_GETADDR requests that send down the wrong struct ifinfomsg [2]. Basically, multiple approaches to solve this have been shut down. Furthermore, the API expressed via RTM_GETADDR is apparently frozen [3] so the wiggle room at this point seems very much zero. The correct solution at this point seems to me to introduce a new RTM_GETADDR2 request. This way we can parse the message and fail hard if the struct is not struct ifaddrmsg and can safely extend it in the future. Userspace tools that rely on the buggy RTM_GETADDR API will still keep working without even having to see any log messages and new userspace tools that want to make user of new features can make use of the new RTM_GETADDR2 requests. [1]: https://lists.openwall.net/netdev/2018/09/25/59 [2]: https://lists.openwall.net/netdev/2018/09/25/75 [3]: https://lists.openwall.net/netdev/2018/09/26/166 Signed-off-by: Christian Brauner Cc: David Ahern Cc: Jiri Benc Cc: Stephen Hemminger --- net/phonet/pn_netlink.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c index 871eaf2cb85e..acba4fe9a612 100644 --- a/net/phonet/pn_netlink.c +++ b/net/phonet/pn_netlink.c @@ -131,13 +131,22 @@ static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr, return -EMSGSIZE; } -static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +static int getaddr_dumpit_common(struct sk_buff *skb, + struct netlink_callback *cb, int rtm_type) { struct phonet_device_list *pndevs; + struct nlattr *tb[IFA_MAX+1]; struct phonet_device *pnd; - int dev_idx = 0, dev_start_idx = cb->args[0]; + int err, dev_idx = 0, dev_start_idx = cb->args[0]; int addr_idx = 0, addr_start_idx = cb->args[1]; + if (rtm_type == RTM_GETADDR2) { + err = nlmsg_parse(cb->nlh, sizeof(struct ifaddrmsg), tb, + IFA_MAX, ifa_phonet_policy, NULL); + if (err < 0) + return err; + } + pndevs = phonet_device_list(sock_net(skb->sk)); rcu_read_lock(); list_for_each_entry_rcu(pnd, &pndevs->list, list) { @@ -168,6 +177,16 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + return getaddr_dumpit_common(skb, cb, RTM_GETADDR); +} + +static int getaddr_dumpit2(struct sk_buff *skb, struct netlink_callback *cb) +{ + return getaddr_dumpit_common(skb, cb, RTM_GETADDR2); +} + /* Routes handling */ static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst, @@ -309,6 +328,8 @@ int __init phonet_netlink_register(void) addr_doit, NULL, 0); rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit, 0); + rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETADDR2, + NULL, getaddr_dumpit2, 0); rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_NEWROUTE, route_doit, NULL, 0); rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE,