Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp2336574pja; Thu, 26 Mar 2020 13:30:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtBI8BJi4dg+Y+hTwVbZaRgz/p/AENB4U/vw2fuRdqTdb0R2SbmKgwFegy5TonXO9ZEDiNW X-Received: by 2002:a9d:2215:: with SMTP id o21mr7559375ota.113.1585254605133; Thu, 26 Mar 2020 13:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585254605; cv=none; d=google.com; s=arc-20160816; b=rcN/TX09Sre4Ef26bITEzkJ4vkrFTjdoYqVe3Nkbi8zMhJaB/DhaK38CZUjceqT+Fv vZnvhzh5gy4JP+bpX0VFKpHWGIQvGiHLvLyItjaF2Uxpwap7LyRT1+TsQwGXGWOU81Fc tkR+gEqeOdL2GXz6iPxTqb1MbbuYKfHbluot1DyEtfgwEX8qeEUadenQKBwKDqE+cvOg nrRfIq0IzvfSIbmDB0zHHK9pORP5GMCvU+MPz6L7j4G8MRDnDOGH2AnU/6ilVifqxaL/ QF9BQBcnU46iHAlzc3rXGM8IfAI5IG+FOHvheuw0YPdnfHBJoZtgBMgAlZvyenTRv1bs mSWA== 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:date:cc:to:from:subject :message-id; bh=c5Q1pWn/VLtR3b88baOWfn1L4Wgx6cJecgpAo8tkeW0=; b=itJwVviyLsH8CsnClN7EicGKvjqCgoumqjnDRnUWd6+/wvpcxQOXT9kOuwN1tu0cyH t8FXCZg3+2ZmR/YTheUXXuUrGuXlIb+/Vpfp0B7Evul8sEHIaQGWTfPafSyDheEVm0M3 7SqVbI9WxSXpCLAMEU3nwIltrrExATetQ/P9fOBA/eGyAfOT+GCtJSr7e4JpOtwzU9a7 bCnRQEtSXna9iSnVXxjPZdus5nzUxLi+rvxtuow+gzwSoYm98bHi2TDeLZ/Fa3dAPtIQ PDJG2Uvd0XYF/F+tImHyMgb90avtDaYnUrepJqn1uRDhw9GdiEt0JGOAwNinAMsxDzly E0Bw== 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 h14si1209821otk.294.2020.03.26.13.29.52; Thu, 26 Mar 2020 13:30:05 -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 S1728862AbgCZU2V (ORCPT + 99 others); Thu, 26 Mar 2020 16:28:21 -0400 Received: from s3.sipsolutions.net ([144.76.43.62]:54802 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728765AbgCZU2K (ORCPT ); Thu, 26 Mar 2020 16:28:10 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1jHZ6j-00CGGW-CK; Thu, 26 Mar 2020 21:28:05 +0100 Message-ID: Subject: Re: [PATCH] kernel/taskstats: fix wrong nla type for {cgroup,task}stats policy From: Johannes Berg To: Andrew Morton , Yafang Shao Cc: bsingharora@gmail.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, David Ahern , "David S.Miller" Date: Thu, 26 Mar 2020 21:28:03 +0100 In-Reply-To: <20200326130808.ccbacd6cba99a40326936fea@linux-foundation.org> References: <1585191042-9935-1-git-send-email-laoar.shao@gmail.com> <20200326130808.ccbacd6cba99a40326936fea@linux-foundation.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-03-26 at 13:08 -0700, Andrew Morton wrote: > (cc's added) > > On Wed, 25 Mar 2020 22:50:42 -0400 Yafang Shao wrote: > > > After our server is upgraded to a newer kernel, we found that it > > continuesly print a warning in the kernel message. The warning is, > > [832984.946322] netlink: 'irmas.lc': attribute type 1 has an invalid length. > > > > irmas.lc is one of our container monitor daemons, and it will use > > CGROUPSTATS_CMD_GET to get the cgroupstats, that is similar with > > tools/accounting/getdelays.c. We can also produce this warning with > > getdelays. For example, after running bellow command > > $ ./getdelays -C /sys/fs/cgroup/memory > > then you can find a warning in dmesg, > > [61607.229318] netlink: 'getdelays': attribute type 1 has an invalid length. And looking at this ... well, that code is completely wrong? E.g. rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET, cmd_type, &tid, sizeof(__u32)); (cmd_type is one of TASKSTATS_CMD_ATTR_TGID, TASKSTATS_CMD_ATTR_PID) or it might do rc = send_cmd(nl_sd, id, mypid, CGROUPSTATS_CMD_GET, CGROUPSTATS_CMD_ATTR_FD, &cfd, sizeof(__u32)); so clearly it wants to produce a u32 attribute. But then static int send_cmd(int sd, __u16 nlmsg_type, __u32 nlmsg_pid, __u8 genl_cmd, __u16 nla_type, void *nla_data, int nla_len) { ... na = (struct nlattr *) GENLMSG_DATA(&msg); // this is still fine na->nla_type = nla_type; // this is also fine na->nla_len = nla_len + 1 + NLA_HDRLEN; // but this??? the nla_len of a netlink attribute should just be // the len ... what's NLA_HDRLEN doing here? this isn't nested // here we end up just reserving 1+NLA_HDRLEN too much space memcpy(NLA_DATA(na), nla_data, nla_len); // but then it anyway only fills the first nla_len bytes, which // is just like a regular attribute. msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len); // note that this is also wrong - it should be // += NLA_ALIGN(NLA_HDRLEN + nla_len) So really I think what happened here is precisely what we wanted - David's kernel patch caught the broken userspace tool. johannes