Received: by 10.223.164.202 with SMTP id h10csp971728wrb; Tue, 7 Nov 2017 18:47:52 -0800 (PST) X-Google-Smtp-Source: ABhQp+T6ARrquKVrstt+JFiiaM/BKVURdkLAgu2GUjfNN+R92TJF2rFdgpJb0FhLlOUmwaBrgERG X-Received: by 10.84.168.69 with SMTP id e63mr775741plb.340.1510109271995; Tue, 07 Nov 2017 18:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510109271; cv=none; d=google.com; s=arc-20160816; b=iyZlIlN6kVHLg+KkUnWDZqlbbYAgyVfYSe3kqgIvx6X16otOkCAw4yaKRsopuvAYxc 5mApMsOlj3KoRHUmlYeY1gnHel0TF80be2pGRE1Kf4JQFQVrmCwieuLt6GEKBtmv4pMA /XgINHviEmfcaoPtLVJXSqWcXn8whvNYlQNfv9oNRkDWIlGnuI7RQ5QCa7c0smHG9S5g fCoYisT4w+zOztzqeajHYqSDDKGvuxGDA4LrkYEdW8F/2krwxmm55AUiL/Ix1tAcTd+M KxTY0J47logU+/nfxGa1+Y6NzjC0pAmKkUx0Lxc1v0tTFB5py5QKi03Jrkd1yCFJT0dI xl/w== 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=R6ysmHAwn0jroLV8dMzuM5TpPPTbACmU1kMgyIzcGqw=; b=cWrhQhXF/2nGIDEiEdlV5zn8Ws3qyuFDX97e3h5oLco2z21kStmN+PI9FGyszkJ11S C213osDN6CkqVLUZcQEuS1tBSJssrEAJ4fRm2PEFOv9lwNyjJfJVFpiX1YlrFQX0dQyB toG5sVr/I7w06nUXhXnYZsRPO8OJfxK5SyhmLwfweiYwFlxpNcpVoEf7iqqtYUPkrapJ U9aRVj6DmLxjpciK6vA9ubnEBvB2DDfasgnHibJjSkankOipgpucVcTUY3G6nChv+Xz9 gn/nuW/KfDP/NUm+t67wn8F/mPzy5G1iU/WuJWJZCO157B4vPhvRsLDB4Fv4RtsBew2l vbFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mpU3hPAx; 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 k3si2441786pld.688.2017.11.07.18.47.38; Tue, 07 Nov 2017 18:47:51 -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=mpU3hPAx; 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 S933957AbdKGVPF (ORCPT + 90 others); Tue, 7 Nov 2017 16:15:05 -0500 Received: from mail-ua0-f193.google.com ([209.85.217.193]:49238 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933768AbdKGVPD (ORCPT ); Tue, 7 Nov 2017 16:15:03 -0500 Received: by mail-ua0-f193.google.com with SMTP id h34so445296uaa.6; Tue, 07 Nov 2017 13:15:03 -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=R6ysmHAwn0jroLV8dMzuM5TpPPTbACmU1kMgyIzcGqw=; b=mpU3hPAxMhEClo1bdbV9dM9bKuArLukd7UBIXXru/xL1qa/F3SgqgPAFCJsYOvC9JU hMsXDaV3maoW1QPaP/8m+kmQ8aT9LOc3p/kVzx0a2JQSYd5o8fT+77hDnRWzOCqt6Zns BPCr3d0kyRpTgLtOhRFPoVnt/XYOaZXgev9qk51RlqugspJjaDZioWTj1gKISlYb+1fZ eFX/nUZ/PwfhxN9sUXVT0eSqiLGdWIWnuAeJcIu95cknBPEbhWMgAEQ9l8fCV8upY8LA eTGKQHIhpBLGAEHHRizBDYiVO6BmEp94yx8ti8XdaGkcIkBvFc5EsfljH/KC5Fi9DZpo 41AA== 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=R6ysmHAwn0jroLV8dMzuM5TpPPTbACmU1kMgyIzcGqw=; b=XnA3e17KsHU9HaI3gKwjNPeSc2NX9xKlvsK4fKnGPU+6uSbK0IhZmHSv0sLmrNwp0I vBom5rK69P3WDrVH9fvhb8ohTIInzTLIwROIGp7/QXr3IZRnMdhC3NWruZ5Z5kCC7K4X //nV06cC0UMLn7A/YflnfsUFLFNMNJzg8DhskDm0/QqUpPoDPhOpFitXbaekR7BGJ6Kz GliDDwP+h9cZW5ZeGGAQdMDl9IA26hmzn1v2L80GuL/7opXiwoQyJMYBOkrJbCx1MHHF dA5YGEpv3mjpmySzCYjHdOzTt5pMUT2VIKymT7oYpaUZQvYt1By6QfFRFPajoYvrwBfT Xnmw== X-Gm-Message-State: AJaThX5j2ypXiBnz7i0gEFgHZrQuRhCOC3hZQoGKAcXsIE4npWQFdYWo 9+3o0YR0KaDJA7KuozRee2cdEjafN8kK7z12ias= X-Received: by 10.176.95.102 with SMTP id z38mr104431uah.100.1510089302692; Tue, 07 Nov 2017 13:15:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.210.14 with HTTP; Tue, 7 Nov 2017 13:14:22 -0800 (PST) In-Reply-To: <1510042830.62prnydrlw.naveen@linux.ibm.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> From: Y Song Date: Tue, 7 Nov 2017 13:14:22 -0800 Message-ID: Subject: Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members To: "Naveen N. Rao" Cc: Alexei Starovoitov , 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 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.... I verified that the drawf info with randomized structure config does not match randomized structure member offset. Specifically, I tried linux/proc_ns.h struct proc_ns_operations, dwarf says: field name: offset 0 field real_ns_name: offset 8 But if you print out the real offset at runtime, you get 40 and 16 respectively. > > - Naveen > > From 1583431287013659873@xxx Tue Nov 07 18:02:30 +0000 2017 X-GM-THRID: 1583027203607239623 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread