Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7275764yba; Thu, 2 May 2019 07:16:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBbW4ZeZZbmcFiZ0A2nMFL0OcbKvtw1ezZCFss51EjoxnoWJJU9A0zKm+cLGErcKCd9EY3 X-Received: by 2002:a63:750c:: with SMTP id q12mr4250061pgc.133.1556806584033; Thu, 02 May 2019 07:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556806584; cv=none; d=google.com; s=arc-20160816; b=v+t8Xi8+0FcvkWY7JxEN+uHKGjZ5uDHRrNlb3Wi3OMH5LfEVy20+fITye4ECYzieP5 +Gc8SSkWZb3fIh3cJ/JzZN//c74slB377wn9rYQnpvieC9GDHAmxJx2jCcswMZQ77OJe SjwJfGjay4Z6RhwcQOp2BcyQORh2Ue09N3HPB8QkTwT3LLYa7TK/bqR6YyQyr1RC4NTF Tnb5GuCKjbIM5s0u8ReISTckFJcb4DS3FzDf0JQhOxmbctoYOpAaUlRTax7NflAyk96/ 2a255rV9TiR+9SKWa4kv4SfXXcaTWIb7dACVn4eQHe9G4qxFn+8VeroZqnJkFi6Cj6cx 2rbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=CL0AXXkAuJYa9pIsMyDlShctgediMlvNNbogKLiSKZ4=; b=daYgyIiylb14QC5V+WXj7OfEBgMnpG691k4pPNVniF30XWxnKAEQ+92CxioTkG6efP mYJy35z7Kfmw+qMo/s1Cw+jKFMYTOOwbU1GbHsNp/EzA3ir0Z+/JVkHLhms4o92lM8yP g4eXelC3hJYLGr9t0Bd/uczqmGER/hWpWpdpaHa5JMsM7qYAXGhJ7YS9w9ha02i6wr1S M3ftjfg+oObTTHSgjhjKrRryyT/5nK9YW+HYQI3VP9bE8X4kwZ51AK/mg1fngnR90R6N auK8E/87iy4aAn6NHdMjg2CPigp80sNX2jaLFoP/3b6RKIan34lVcXokr5CVVeYxIvG7 2w9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb2si13810541plb.383.2019.05.02.07.16.09; Thu, 02 May 2019 07:16:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726446AbfEBOPN (ORCPT + 99 others); Thu, 2 May 2019 10:15:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:51400 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726310AbfEBOPM (ORCPT ); Thu, 2 May 2019 10:15:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7C0B0AD8C; Thu, 2 May 2019 14:15:11 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id CD0F5E00D0; Thu, 2 May 2019 16:15:10 +0200 (CEST) Message-Id: <5368071b5e287d50cf3a93805746217a2f36ff69.1556806084.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 1/3] genetlink: do not validate dump requests if there is no policy To: "David S. Miller" Cc: netdev@vger.kernel.org, Johannes Berg , David Ahern , linux-kernel@vger.kernel.org Date: Thu, 2 May 2019 16:15:10 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unlike do requests, dump genetlink requests now perform strict validation by default even if the genetlink family does not set policy and maxtype because it does validation and parsing on its own (e.g. because it wants to allow different message format for different commands). While the null policy will be ignored, maxtype (which would be zero) is still checked so that any attribute will fail validation. The solution is to only call __nla_validate() from genl_family_rcv_msg() if family->maxtype is set. Fixes: ef6243acb478 ("genetlink: optionally validate strictly/dumps") Signed-off-by: Michal Kubecek Reviewed-by: Johannes Berg --- net/netlink/genetlink.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 72668759cd2b..9814d6dbd2d6 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -537,21 +537,25 @@ static int genl_family_rcv_msg(const struct genl_family *family, return -EOPNOTSUPP; if (!(ops->validate & GENL_DONT_VALIDATE_DUMP)) { - unsigned int validate = NL_VALIDATE_STRICT; int hdrlen = GENL_HDRLEN + family->hdrsize; - if (ops->validate & GENL_DONT_VALIDATE_DUMP_STRICT) - validate = NL_VALIDATE_LIBERAL; - if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) return -EINVAL; - rc = __nla_validate(nlmsg_attrdata(nlh, hdrlen), - nlmsg_attrlen(nlh, hdrlen), - family->maxattr, family->policy, - validate, extack); - if (rc) - return rc; + if (family->maxattr) { + unsigned int validate = NL_VALIDATE_STRICT; + + if (ops->validate & + GENL_DONT_VALIDATE_DUMP_STRICT) + validate = NL_VALIDATE_LIBERAL; + rc = __nla_validate(nlmsg_attrdata(nlh, hdrlen), + nlmsg_attrlen(nlh, hdrlen), + family->maxattr, + family->policy, + validate, extack); + if (rc) + return rc; + } } if (!family->parallel_ops) { -- 2.21.0