Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4916753imc; Mon, 25 Feb 2019 13:34:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IZuPd4SdjTs+LZBDdC8jJSY0zIW9N2rdAMtFhijibvMKwOVLbNyPC3DCRsTJsWo9UJPyyst X-Received: by 2002:a62:1551:: with SMTP id 78mr1866358pfv.45.1551130479555; Mon, 25 Feb 2019 13:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130479; cv=none; d=google.com; s=arc-20160816; b=lmAAz5IKViM53ZahYkwvuYQbWo3Xfbv7Eje4Ao8zeUsz47A2qW4iu6auTw+7C/CKGD jXNW51tyjI2tmh1bEYen73gpL9bI+KyteOpUNDebRb99MOyzIShgu67tAD2x8kCwKs59 ABzxnpmRwwVPLFeCyymHdQ7wfmKbUleOGGoOwDW7XZKFkM5FqWjKnyD8Q91B7X+2fqDb il7UbDCOYSbJD2bCvUECYErhncneVppFoWmIhpDHAg9GuQEMcJeSPFgIvVfpO5e1qs0M WzbgFPKHii+6M0x4r72vLbK6G1kMv57b/UGAAFhIIFTP0R33DRXkb+9YRet/b/zWyNtO p+mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=adiPtPCh7JIcdxT79qUVVdsjad7wZ50xuzERA4zh+Yc=; b=aZNb5Y+G84NXt5TZPxWl00kg5Y0+oXutNW2awYP/coRyisRNRGQNVF7scb8vzFrc3P 4LfQSz11IycWRYMJgD+0fHLhYRG8/1AWthyZh4WkFtDZ5adXmTpd06/QGjgwer2WtqZP 5i1rWBu0WBc6z59KKYuShWc18Ivg7CfM7WYawPfiYyn2VlzQ9o6ti1qAtdX+fC9CwbYO 7h20WTLKnVLDRNpZ9pa1zsPUgs1ylXkancK1kJlX0r4etzoNz1RVdHz00nlNcSRAJM6v dQLU1jA+yRrftOMCVCd1s1glPZXq0ArerNN1UnbB3wxz0eurl2GSum29n2hmUbHjjch5 nJJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TMCfslfo; 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 s11si10447116pgk.344.2019.02.25.13.34.24; Mon, 25 Feb 2019 13:34:39 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=TMCfslfo; 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 S1732453AbfBYVeH (ORCPT + 99 others); Mon, 25 Feb 2019 16:34:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:40350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727592AbfBYVeG (ORCPT ); Mon, 25 Feb 2019 16:34:06 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 656DF20578; Mon, 25 Feb 2019 21:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130444; bh=KzmUuGrcQ/aepzv9n0vOahl2Xm4gB559Fzx1f064mrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TMCfslfoiLgHQvlXc65SeEKk3RFWqKEyaHE/Jr1YgfIGkz6ra38gpUL7H1NI4Eg06 X9uS820ZsdvEgtcdc8uuPs/FKia4U4/VJo89Nhuc01OAmfJ2uMHdrC6pFxM7+LtnBs XM1SkCC1LyaPtAdIMxr2aWXcT1bHWExlY8sAWsTs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , "David S. Miller" Subject: [PATCH 4.20 123/183] inet_diag: fix reporting cgroup classid and fallback to priority Date: Mon, 25 Feb 2019 22:11:36 +0100 Message-Id: <20190225195115.441792555@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Konstantin Khlebnikov [ Upstream commit 1ec17dbd90f8b638f41ee650558609c1af63dfa0 ] Field idiag_ext in struct inet_diag_req_v2 used as bitmap of requested extensions has only 8 bits. Thus extensions starting from DCTCPINFO cannot be requested directly. Some of them included into response unconditionally or hook into some of lower 8 bits. Extension INET_DIAG_CLASS_ID has not way to request from the beginning. This patch bundle it with INET_DIAG_TCLASS (ipv6 tos), fixes space reservation, and documents behavior for other extensions. Also this patch adds fallback to reporting socket priority. This filed is more widely used for traffic classification because ipv4 sockets automatically maps TOS to priority and default qdisc pfifo_fast knows about that. But priority could be changed via setsockopt SO_PRIORITY so INET_DIAG_TOS isn't enough for predicting class. Also cgroup2 obsoletes net_cls classid (it always zero), but we cannot reuse this field for reporting cgroup2 id because it is 64-bit (ino+gen). So, after this patch INET_DIAG_CLASS_ID will report socket priority for most common setup when net_cls isn't set and/or cgroup2 in use. Fixes: 0888e372c37f ("net: inet: diag: expose sockets cgroup classid") Signed-off-by: Konstantin Khlebnikov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/inet_diag.h | 16 +++++++++++----- net/ipv4/inet_diag.c | 10 +++++++++- net/sctp/diag.c | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) --- a/include/uapi/linux/inet_diag.h +++ b/include/uapi/linux/inet_diag.h @@ -137,15 +137,21 @@ enum { INET_DIAG_TCLASS, INET_DIAG_SKMEMINFO, INET_DIAG_SHUTDOWN, - INET_DIAG_DCTCPINFO, - INET_DIAG_PROTOCOL, /* response attribute only */ + + /* + * Next extenstions cannot be requested in struct inet_diag_req_v2: + * its field idiag_ext has only 8 bits. + */ + + INET_DIAG_DCTCPINFO, /* request as INET_DIAG_VEGASINFO */ + INET_DIAG_PROTOCOL, /* response attribute only */ INET_DIAG_SKV6ONLY, INET_DIAG_LOCALS, INET_DIAG_PEERS, INET_DIAG_PAD, - INET_DIAG_MARK, - INET_DIAG_BBRINFO, - INET_DIAG_CLASS_ID, + INET_DIAG_MARK, /* only with CAP_NET_ADMIN */ + INET_DIAG_BBRINFO, /* request as INET_DIAG_VEGASINFO */ + INET_DIAG_CLASS_ID, /* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG, __INET_DIAG_MAX, }; --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c @@ -108,6 +108,7 @@ static size_t inet_sk_attr_size(struct s + nla_total_size(1) /* INET_DIAG_TOS */ + nla_total_size(1) /* INET_DIAG_TCLASS */ + nla_total_size(4) /* INET_DIAG_MARK */ + + nla_total_size(4) /* INET_DIAG_CLASS_ID */ + nla_total_size(sizeof(struct inet_diag_meminfo)) + nla_total_size(sizeof(struct inet_diag_msg)) + nla_total_size(SK_MEMINFO_VARS * sizeof(u32)) @@ -287,12 +288,19 @@ int inet_sk_diag_fill(struct sock *sk, s goto errout; } - if (ext & (1 << (INET_DIAG_CLASS_ID - 1))) { + if (ext & (1 << (INET_DIAG_CLASS_ID - 1)) || + ext & (1 << (INET_DIAG_TCLASS - 1))) { u32 classid = 0; #ifdef CONFIG_SOCK_CGROUP_DATA classid = sock_cgroup_classid(&sk->sk_cgrp_data); #endif + /* Fallback to socket priority if class id isn't set. + * Classful qdiscs use it as direct reference to class. + * For cgroup2 classid is always zero. + */ + if (!classid) + classid = sk->sk_priority; if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid)) goto errout; --- a/net/sctp/diag.c +++ b/net/sctp/diag.c @@ -256,6 +256,7 @@ static size_t inet_assoc_attr_size(struc + nla_total_size(1) /* INET_DIAG_TOS */ + nla_total_size(1) /* INET_DIAG_TCLASS */ + nla_total_size(4) /* INET_DIAG_MARK */ + + nla_total_size(4) /* INET_DIAG_CLASS_ID */ + nla_total_size(addrlen * asoc->peer.transport_count) + nla_total_size(addrlen * addrcnt) + nla_total_size(sizeof(struct inet_diag_meminfo))