Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4517389pxa; Mon, 10 Aug 2020 10:59:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3X29tnPaXUaNZrBEaBo0AyudNU8f8J39aVcOPlqaIcn8rC9NFne9w0tcRF7XLPMtmaDNX X-Received: by 2002:a17:906:a88b:: with SMTP id ha11mr22277466ejb.545.1597082397272; Mon, 10 Aug 2020 10:59:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1597082397; cv=pass; d=google.com; s=arc-20160816; b=QiBFK4atSZEUyGCcebyEKbO0y1+/KF0ukdY6azaogiOfX9VOPsEPwxVh/UVDHHuSjm EZ0yczMAqIciO2e5Z5YfBLBkHQv6v59eB4Igeg2rPW2RgevsfezVkhPGMlR5rkbF7zKY CPlpZzGDiWV8ZGUZF4Sl+MJxf17d/sUKoJy4aLUaBc4qJVLAjX/Lx8+erBSMBrCJwJYS G1Bq5udTm/Cl56ZMjaeim3m4kC2Sy3UD8JVz7E3eYe5ZHfxPZtxg5GT7IiZdF2LgWpLD ntrwovxvBcq8nLaeXF0nx0m4syDcJrzwJDu0755oKaJufwwP+1PXaVuJ4qhIbqjUtmeu F1gQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:in-reply-to :content-disposition:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=CnUH8wFbRH3D+x8tqc+88oybqYHc36iotQkG9C3ikb0=; b=E0dWod4jQd8ALU5tvHG6kDetvRJJZWNfTl8VgBQlmYPmDgV8jRM/Vm1V9hdRL0b/st cnfXx+0D+X7pEq7IuRGB4WRD4isgbifZAqxoouyk4uUsPd03LJ253Knh583MMLdiW9os YHRnDKnUh2kFquTh84i3rBocffPb+gR2LJkbW9adaHECB2adrSK8cEv9rk7kORo8wFLk 2uBJwtxEDUj0BYckZEL8U+eKrIwqLNEcnkN3oetJL4OHbqKM8vMXvlZywdDaGwSo/sVZ c+0FhfOtn2SWwrAw+6ngaqOpf+fM0XEICbHfliMdv89XrTI0oBpdrgmQj5fhk1RnSv+h pLDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=QzEP54Xz; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=Jiqk9UNV; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si11508019ejk.250.2020.08.10.10.59.34; Mon, 10 Aug 2020 10:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=QzEP54Xz; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=Jiqk9UNV; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgHJR46 (ORCPT + 99 others); Mon, 10 Aug 2020 13:56:58 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:18200 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726820AbgHJR46 (ORCPT ); Mon, 10 Aug 2020 13:56:58 -0400 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07AHswQM025142; Mon, 10 Aug 2020 10:56:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=facebook; bh=CnUH8wFbRH3D+x8tqc+88oybqYHc36iotQkG9C3ikb0=; b=QzEP54XzoX92uHMBw5QAlHt2bZtjeFXUK+02D7Ojdon20PtcDPLsKecHN0MsLNZFZU1y TGuqbL30iRaeY+J/es9tNXKqTSI1yvEY4bja4ADt1FUCREdU3ILct49kT0PSpkiy0o6O 1pFYzwSgxR+M+EBwZgfp3pbWNhFcynrJp0Y= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 32ssjk8e0r-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 10 Aug 2020 10:56:36 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (100.104.98.9) by o365-in.thefacebook.com (100.104.94.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 10 Aug 2020 10:56:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aFsU39TyngPX0BrUj+rxedqHWYw1ySC+mV3pbS+Y0aTsjug/WmqhWuP/7Of0V9osLMFowD6DbJP2exF/vF3eh5I/eSmxiDsd85kfvKG+Cp8CCN8n5LnyMojqHRqveSP1eiBZeK/55GIYm4yDOZNXzXqCZ4lehiVqFP+HgeJMqc45NqLd3t3oh9fMM/O2fGyZNL5kYk4v4KF29HIqlul3fwtLcwiFiZR2sa9/MitPyYqkSSxh/3TU469BkZW2+fuzFMS9RaGJbB01sLvgpH99Z8yrzHgAOd2r2CdcKnAQwoFfZR0wCw1OtIQyXokilktktTpVYPmVIdb7wZ12RCNWaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CnUH8wFbRH3D+x8tqc+88oybqYHc36iotQkG9C3ikb0=; b=gZMhdLKe61H5LdYAlpa+ZgUdcu71luHB7ntAbtKs2PgaLW9LxmqCDba4HRYkqxDgr3fY+nQa9/Ow4frMjcjo+v8JiJAdASManVjo2h/ZzRlKdW8KWsLpEhP7r97oKox+uZuI0UFpWydx/p7YKvlG+4xt10aI1yOaAQgQaIQ+A1WDVeVtqucyxj24+Yh7F7yX5/Vy+SB+QHvaGbe+eXDbNlQXmxcK7NBpA3g+8mQ2RE8bE2NLsJCkhUucZHJKPWwGivivK8Nzry9k05QpKrtOsSyKwN2Z3L8CBTfWOVQR20mmMMiOcQTmDedvHD5alTdrNIl0B3bDFamaCMLAdlnvRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector2-fb-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CnUH8wFbRH3D+x8tqc+88oybqYHc36iotQkG9C3ikb0=; b=Jiqk9UNVG8L3SeMfQTbokmxerh5A6L4AYXG8v+92UUrhNn/FSBl+gC7oZdg54RrdjepYacpOAs+MDmLB6SUdxNyj6sSiBMYW+XH65GjNuyb2c508eFA9T5fbtBYGVdwA6pyMbzeW62jKckTfTA6JK0mW0LhIpSrbPAYXtFNQ9so= Authentication-Results: vivo.com; dkim=none (message not signed) header.d=none;vivo.com; dmarc=none action=none header.from=fb.com; Received: from BY5PR15MB3571.namprd15.prod.outlook.com (2603:10b6:a03:1f6::32) by BYAPR15MB3301.namprd15.prod.outlook.com (2603:10b6:a03:101::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Mon, 10 Aug 2020 17:56:20 +0000 Received: from BY5PR15MB3571.namprd15.prod.outlook.com ([fe80::d489:8f7f:614e:1b99]) by BY5PR15MB3571.namprd15.prod.outlook.com ([fe80::d489:8f7f:614e:1b99%7]) with mapi id 15.20.3261.024; Mon, 10 Aug 2020 17:56:20 +0000 Date: Mon, 10 Aug 2020 10:56:14 -0700 From: Martin KaFai Lau To: Jiang Yu CC: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Eric Dumazet , Jakub Sitnicki , zhanglin , Kees Cook , Andrey Ignatov , Quentin Monnet , , , , Subject: Re: [PATCH] bpf: Add bpf_skb_get_sock_comm() helper Message-ID: <20200810175529.qdsbziyoo6myw2dr@kafai-mbp.dhcp.thefacebook.com> References: <20200810131014.12057-1-jyu.jiang@vivo.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200810131014.12057-1-jyu.jiang@vivo.com> X-ClientProxiedBy: BYAPR06CA0017.namprd06.prod.outlook.com (2603:10b6:a03:d4::30) To BY5PR15MB3571.namprd15.prod.outlook.com (2603:10b6:a03:1f6::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kafai-mbp.dhcp.thefacebook.com (2620:10d:c090:400::5:458c) by BYAPR06CA0017.namprd06.prod.outlook.com (2603:10b6:a03:d4::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Mon, 10 Aug 2020 17:56:20 +0000 X-Originating-IP: [2620:10d:c090:400::5:458c] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1879d0e-368a-437f-b12e-08d83d56b026 X-MS-TrafficTypeDiagnostic: BYAPR15MB3301: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-FB-Source: Internal X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L+0j7ybD4OBBmOnpwB/Dx+m1zVjnNZThkj78JVaFgyazH4xvrbcNJbA/QxMuezOdIAhYRfpBneqVWpw0xJ+lTKqQAKAuhlSkzKj4nCD8UhdFFkGQrY92XlXBKhzDaWdU2F0FPcbsDKaypa1yaPXbSTHH9HTnR2YWcLpqSf/QF/kDzXaiYJ2TSd0BbZFs3ruILAI9OhAG2Ba/R01RAP2H2L9ffFFLR4j07ajONXtQI60s49U5YXp687kJeYUSF54Zp0G1OwwkhBlWF6Ca21QLSagULRRRYr6S+j8jW87j3PiRhsmHc7LCAUI4lhYaB2azVIPF6OzBgQR+NCSn0EjQtg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR15MB3571.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(376002)(39860400002)(346002)(396003)(136003)(366004)(5660300002)(4326008)(55016002)(8676002)(6916009)(6506007)(186003)(86362001)(2906002)(16526019)(478600001)(7416002)(52116002)(7696005)(66556008)(83380400001)(66476007)(9686003)(8936002)(54906003)(66946007)(6666004)(316002)(1076003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: FSWSai3Av/zpWNzopHDWTFwyScCNNrpdDmpSh0wVCrRTaqNvOfrtMJMplV7H92XeOUwrXaGUyjLKacZmIqOcMGKxUGsq43T9f9vDCoa0Pshq7WEtClujUePbYO1ps60Dj+Y7Uktir/0B9ZCH/F8vyksKKLWbtXq8GcBa4vqEZiYCD6WRxK72pS1OGKX+jiTgXHuOT/7gXeUPtfnfT0j1jMqYxe+dipR8ejh1gdkDXfLX4moAr77mKY7ZhUV5YChA2Z0CNLDeHc6M9uheCOPS2zPNRCNjnkEGjjBR7i8Xck/ubLkEAX87P9TvokLb5gg5VhScmXwypKahR9C2E6//VeDe/q7u45uKCzFOz8XO1q+UX7SFFJvMI5Lx/XXm54cOzZYp2Aw9beL9IAPRqqUQTk0D+RLvro93dN3OmW/oaojsBwXe/kiJUPB4PntoL+cy+EGXHcD0GDz9qZvLm66IPXtbzdDkyPL6O4Xil5Kl+CWQdWgM24Orzlg7Dow+XeZTNuGVn8zSVJjjAPKdSmJRl3l2zHco2EPVtBqmZuLaZw4rOeNcJDeAdPsCrFIXzbPRJ6seMydCtJ2iQdX3rVEE09Jad2sYCYxmsowmeNI/GeGCICv56yAJxCeGbmu3RY6YIKwmU0sAFZCMM36mE6GBRU+jzBvIGKb9d8I2BTZLsKw= X-MS-Exchange-CrossTenant-Network-Message-Id: b1879d0e-368a-437f-b12e-08d83d56b026 X-MS-Exchange-CrossTenant-AuthSource: BY5PR15MB3571.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2020 17:56:20.7321 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wcwQKB9ataZsoRA//wUtFANEb+rPRIN8KG6+xIDaryD71o8JkOMDjuH/U3ILPeA0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB3301 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-10_15:2020-08-06,2020-08-10 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1011 phishscore=0 suspectscore=1 bulkscore=0 adultscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008100126 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 10, 2020 at 06:09:48AM -0700, Jiang Yu wrote: > skb distinguished by uid can only recorded to user who consume them. > in many case, skb should been recorded more specific to process who > consume them. E.g, the unexpected large data traffic of illegal process > in metered network. > > this helper is used in tracing task comm of the sock to which a skb > belongs. > > Signed-off-by: Jiang Yu > --- > include/net/sock.h | 1 + > include/uapi/linux/bpf.h | 1 + > net/core/filter.c | 32 ++++++++++++++++++++++++++++++++ > net/core/sock.c | 20 ++++++++++++++++++++ > tools/include/uapi/linux/bpf.h | 1 + > 5 files changed, 55 insertions(+) > > diff --git a/include/net/sock.h b/include/net/sock.h > index 064637d1ddf6..9c6e8e61940f 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -519,6 +519,7 @@ struct sock { > #ifdef CONFIG_BPF_SYSCALL > struct bpf_sk_storage __rcu *sk_bpf_storage; > #endif > + char sk_task_com[TASK_COMM_LEN]; One possibility is to use the "sk_bpf_storage" member immediately above instead of adding "sk_task_com[]". It is an extensible sk storage for bpf. There are examples in selftests, e.g tools/testing/selftests/bpf/progs/udp_limits.c which creates sk storage at socket creation time. Another hook point option could be "connect()" for tcp, i.e. "cgroup/connect[46]". Search "BPF_MAP_TYPE_SK_STORAGE" under the selftests/bpf for other examples. It seems there is already a "bpf_get_current_comm()" helper which could be used to initialize the task comm string in the bpf sk storage. btw, bpf-next is still closed.