Received: by 10.223.164.202 with SMTP id h10csp987199wrb; Tue, 7 Nov 2017 19:09:24 -0800 (PST) X-Google-Smtp-Source: ABhQp+TePzCPvEZDIpVDS3RtxHZlDcJgSX55eoSxxOGtar/WklZ9sH4qROPpgYFkAw5PximWHQ7l X-Received: by 10.84.233.12 with SMTP id j12mr790579plk.420.1510110564461; Tue, 07 Nov 2017 19:09:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510110564; cv=none; d=google.com; s=arc-20160816; b=PQlwBdAPVv3kQI/gW09ldqGVNDrcN0zis3LaOXVV6CAo/dCK6rOR43zkqjROk12GMy P0AaQ5fmnhjmUX6i+D2PzrCACOgIfngDA9e7hMjdztDljd6QG+W3ZEm4PiaolBMcxzvn dA60ZYf/7N9g2I8dHRnL4QDHkHfY5RimPlf1c8f3u+nKUYb8I0+ROJIfgin23Vm9kLBT SCCDYNuiLKLtVsSSmhbqLj6PYv8g+oX6CNYrayfqv9m1Pgjp0iHnZnLmzSHN2x5Ipcw0 55G4rnUqxt5+ldD2ht2B89JxAgdmi1q3O90XHWL1K3AAOHF2hltqdyN3aD2OK5JR5x3m PKBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=hbnf+wDcsLvTJ6mLuspJQD6gBAnK3fYupTSyZ376vRk=; b=erqugl6ahptBeAgODlh6JpDB/E4aATRP65hr+RxEFz9m8y5551xSnU1vU4FTOzabxy PuWNgV8gEh4BnMDcVbS4HtoGVy2iEJiW9vl+sFJLulRAFx/VrA0IESOwsBI+X8k2pmic D8GeBJge5dLE916VjJj3oGOx0BZY4VM+IIWmAD6RbNAP0J3az2KrvgYnv2nUBmP1lR8N pfOVkB7fc17T8VqS66vVeYz4Vwz76EhvZexeXa5QitCGFCIXH9eqY24JgaSEiUyJvpTF fXtvW8ot7eu93htFd+iQRVr+XkuYVu5gEtMj25b42g21LY3NpELGw1XIY1nuAk5BbH2r q6Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vdtaDDp6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si2662480pfh.239.2017.11.07.19.09.11; Tue, 07 Nov 2017 19:09:24 -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=@gmail.com header.s=20161025 header.b=vdtaDDp6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754953AbdKGWn3 (ORCPT + 90 others); Tue, 7 Nov 2017 17:43:29 -0500 Received: from mail-vk0-f65.google.com ([209.85.213.65]:51816 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752046AbdKGWn1 (ORCPT ); Tue, 7 Nov 2017 17:43:27 -0500 Received: by mail-vk0-f65.google.com with SMTP id v3so548667vkb.8; Tue, 07 Nov 2017 14:43:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hbnf+wDcsLvTJ6mLuspJQD6gBAnK3fYupTSyZ376vRk=; b=vdtaDDp69BXLuhWjo7H48//M5vLzVO0S7dPEq3bLI+XPNoXrUpJq++3CzfjtfIopt5 I0cgA7FmEzJDWtjPBKlgG6IT8I4Skm0Kn5gdEVJLr0gwwvQGbRCjmUJ4X4LdlZTdv9u8 G3x+hvxlP7Ditd56QVS9khK1Kednb1XaIE7OdH3LabvzPWPRHe1yze2NK+UrlZYZ5Tkz VKmCzdcIBKhMiPjyNBhsOnUrp4VwwGO875KEHon8y34qyixc26JTz4+dUCF1n5prD3oT 510kf6W5FybFYAGR/gwTww4+/iRFQ5ZdwDUM4XOQ8yAnbpGuqPup5xrpZ/JCTdOUhH5n EwEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hbnf+wDcsLvTJ6mLuspJQD6gBAnK3fYupTSyZ376vRk=; b=GUom57AzmLmzEbI+f6PjjMZ1kO26/j7XdByHwRf4moatCqYgd2fzrj7A+CuO8wvDGq nW6gZMMEstVgjHhgzj2qu/70JYEKGSPjTywD9YPM2c2yZZ1IZavoIDz94vupb9DoWsCF 5ONSRwCSIbdpXuBpedPap7QXG2B8b71+gixToTcZkQoU7OH2ekqS5S4fyjCw2xtdTW5K rqcYvjSzKjrkIL8982keOsjueYwsfPviNEWiMOLAspYDgGgz6ctLhIcUGJhY5/W5XL2K 4D8UDQGBNPROOXyHrRduc7PR3TB31wAEuWPRNCeSVFJeXa9qrxCwtgW23wtvakduNk9/ uqAw== X-Gm-Message-State: AJaThX4Z39xadviibA0ck6NQzMsBdjVzokaJ2BcY02bGJ3kD0pPTBjB0 znzl/ptolhBYZicOmZDF+7X3T7XWE5sSUMp+8cE= X-Received: by 10.31.141.4 with SMTP id p4mr250301vkd.53.1510094606546; Tue, 07 Nov 2017 14:43:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.210.14 with HTTP; Tue, 7 Nov 2017 14:42:46 -0800 (PST) In-Reply-To: <328c2dff-7d6d-0dc0-46cf-ae715845903e@fb.com> References: <20171103065833.8076-1-sandipan@linux.vnet.ibm.com> <94a4761f-1b51-8b70-fb7f-3cea91c69717@fb.com> <1509815348.8zu63uatdo.naveen@linux.ibm.com> <4acdc081-341d-ee91-a591-b1d331a8c8d5@fb.com> <1509982000.092la4257a.naveen@linux.ibm.com> <1510042830.62prnydrlw.naveen@linux.ibm.com> <328c2dff-7d6d-0dc0-46cf-ae715845903e@fb.com> From: Y Song Date: Tue, 7 Nov 2017 14:42:46 -0800 Message-ID: Subject: Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members To: Alexei Starovoitov Cc: "Naveen N. Rao" , netdev , Sandipan Das , Brendan Gregg , Daniel Borkmann , Martin KaFai Lau , Kees Cook , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 7, 2017 at 2:04 PM, Alexei Starovoitov wrote: > On 11/8/17 6:47 AM, Y Song wrote: >> >> On Tue, Nov 7, 2017 at 1:39 PM, Alexei Starovoitov wrote: >>> >>> On 11/8/17 6:14 AM, Y Song wrote: >>>> >>>> >>>> On Tue, Nov 7, 2017 at 12:37 AM, Naveen N. Rao >>>> wrote: >>>>> >>>>> >>>>> Alexei Starovoitov wrote: >>>>>> >>>>>> >>>>>> >>>>>> On 11/7/17 12:55 AM, Naveen N. Rao wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I thought such struct shouldn't change layout. >>>>>>>> If it is we need to fix include/linux/compiler-clang.h to do that >>>>>>>> anon struct as well. >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> We considered that, but it looked to be very dependent on the version >>>>>>> of >>>>>>> gcc used to build the kernel. But, this may be a simpler approach for >>>>>>> the shorter term. >>>>>>> >>>>>> >>>>>> why it would depend on version of gcc? >>>>> >>>>> >>>>> >>>>> >>>>> From what I can see, randomized_struct_fields_start is defined only for >>>>> gcc >>>>>> >>>>>> >>>>>> = 4.6. For older versions, it does not get mapped to an anonymous >>>>> >>>>> >>>>> structure. We may not care for older gcc versions, but.. >>>>> >>>>> The other issue was that __randomize_layout maps to __designated_init >>>>> when >>>>> randstruct plugin is not enabled, which is in turn an attribute on gcc >>>>> >= >>>>> v5.1, but not otherwise. >>>>> >>>>>> We just need this, no? >>>>>> >>>>>> diff --git a/include/linux/compiler-clang.h >>>>>> b/include/linux/compiler-clang.h >>>>>> index de179993e039..4e29ab6187cb 100644 >>>>>> --- a/include/linux/compiler-clang.h >>>>>> +++ b/include/linux/compiler-clang.h >>>>>> @@ -15,3 +15,6 @@ >>>>>> * with any version that can compile the kernel >>>>>> */ >>>>>> #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), >>>>>> __COUNTER__) >>>>>> + >>>>>> +#define randomized_struct_fields_start struct { >>>>>> +#define randomized_struct_fields_end }; >>>>>> >>>>>> since offsets are mandated by C standard. >>>>> >>>>> >>>>> >>>>> >>>>> Yes, this is what we're testing with and is probably sufficient for our >>>>> purposes. >>>> >>>> >>>> >>>> Just tested this with bcc. bcc actually complains. the rewriter >>>> is not able to rewrite prev->pid where prev is "struct task_struct >>>> *prev". >>>> I will change bcc rewriter to see whether the field value is correct or >>>> not. >>>> >>>> Not sure my understanding is correct or not, but I am afraid that >>>> the above approach for clang compiler change may not work. >>>> If clang calculates the field offset based on header file, the offset >>>> may not be the same as kernel one.... >>> >>> >>> >>> why is that? >>> When randomization is off both gcc and clang must generate the same >>> offsets, since it's C standard. >> >> >> The patch changed compiler-clang.h, so gcc still do randomization. > > > gcc_plugins are off by default and randomization will not be > turned on for any sane distro or datacenter that cares about > performance and stability. > So imo above compiler-clang.h patch together with bcc fix would > be enough. Agree that short time the suggested fix should be enough. Long time, disto could become "insane" someday :-) From 1583464915287567078@xxx Wed Nov 08 02:57:00 +0000 2017 X-GM-THRID: 1583027203607239623 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread