Received: by 10.192.165.156 with SMTP id m28csp1408687imm; Wed, 18 Apr 2018 09:10:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx49rKSOmoT9cdVEfmbTI3m75e3enm8CFVZlA4hHPx1x8OzpXW1xkmTg35Q4H1UKdHhykn+bl X-Received: by 2002:a17:902:a70c:: with SMTP id w12-v6mr2603198plq.74.1524067843517; Wed, 18 Apr 2018 09:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524067843; cv=none; d=google.com; s=arc-20160816; b=JZP9nOMTlYGKPWq3HI132RwoppEh+v0dF8qG3WZMcssJB6xwQuvLgtsSR0+4o4EGaF yUnkLh7GBUXB5RigcTbT1WbRh7QMnIupJTH8MAY8Knp471TCKIK6Ri2X4DB+wA/DY/RR A5Ct+d2zLACGneY8QBCGZgs+Vs54A2wEeUc10/d5XO0KD15Jiojtb3h9PK3GWiOzIgqJ J7huKBsZ3PxxryFEVpY8x4ioIMYq3aKbcFGZtE4r7rhzvmBX0Ye5Hi8DBIP+dDBoWs+F GrUR7aC6I2mpLoyVTNAJTxUmAWVZVl9COe39v6/j6GeekqHc2Nvp3vSj2Ql/6iSoeJpk g3uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature:arc-authentication-results; bh=6wT/BE+/Ne8JGoTfzCSUyGN8+eGLMp32xQY+p0PmIpw=; b=C8lXT2oC1HFqhrlx1Eom2dAhbv4TbDj/OeVEJLH5YHWZsLi/5wGPsIODQBQ5msw/ZO 1c3XstfJMN0L9sLYVfWxfcrAMwvAm4DOcZ9N/2/h4zr3MMB0m6e9Gguo5HEUdlpQFAEe +SyrlqxScWQ4bBchozUy9DjmXkmsvK4uINiwhTkyTlWKsq6zM8r5ICZ08Po2w5vGMlmS W6PNRT5Mx+K4S0jKB6QCTOLJ9yyWI1U8BfKzdebqCW6IoRLpffC3O6JqB1HPfGwJVewv vSpJopOzmqGrOlsocLWoZ4AxSMZMs/QRGWzN+k3IG61WhU+fukcjZxmL3i9ZyHsZdMY8 bVLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=NFaCjG/j; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=KpDi3S/z; 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=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay5-v6si1434753plb.208.2018.04.18.09.10.28; Wed, 18 Apr 2018 09:10:43 -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; dkim=pass header.i=@fb.com header.s=facebook header.b=NFaCjG/j; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=KpDi3S/z; 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=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752407AbeDRQJV (ORCPT + 99 others); Wed, 18 Apr 2018 12:09:21 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34242 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751431AbeDRQJT (ORCPT ); Wed, 18 Apr 2018 12:09:19 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3IG7lmD015288; Wed, 18 Apr 2018 09:08:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=6wT/BE+/Ne8JGoTfzCSUyGN8+eGLMp32xQY+p0PmIpw=; b=NFaCjG/jxxbWrercwo/NX+7r++QreGhZSO1xrm59fe7IYoBrSrb2mdpgSLpgXrNGR7rI cz0CM+IlpLONW/1jLeJBFRrGI469lSMXxmZRsinBUDptqwAZ3e7s8ourA3THypOD+LCc ammtvPcmIwvX6hCaSgMYZKB2GtNlK6RNk8c= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2he8ka04xg-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 18 Apr 2018 09:08:53 -0700 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.22) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Apr 2018 09:08:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6wT/BE+/Ne8JGoTfzCSUyGN8+eGLMp32xQY+p0PmIpw=; b=KpDi3S/zO6EIQk+b7e6S1xib7fbhCClKpVsSAKqOPgwUWd6w2JTIGwsYhhbPiukIlfHlj1i148kebkp6OrjqOn0h/QrRo7FxhQ51zwoHpTjonmvyTGtQkGO7TCpRGm9vbcwSeiz4QLSxJ/MyANJSHk8Xg9nlU+2rhCPqmuEBklQ= Received: from DM5PR15MB1548.namprd15.prod.outlook.com (10.173.222.139) by DM5PR15MB1689.namprd15.prod.outlook.com (10.175.112.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Wed, 18 Apr 2018 16:08:50 +0000 Received: from DM5PR15MB1548.namprd15.prod.outlook.com ([fe80::d87a:fa34:57e7:1e2c]) by DM5PR15MB1548.namprd15.prod.outlook.com ([fe80::d87a:fa34:57e7:1e2c%17]) with mapi id 15.20.0675.015; Wed, 18 Apr 2018 16:08:50 +0000 From: Song Liu To: Miklos Szeredi CC: LKML , Kernel Team , Steven Rostedt , Ingo Molnar , "Howard McLauchlan" , Josef Bacik , "Srikar Dronamraju" Subject: Re: [PATCH 1/2] tracing: fix bad use of igrab in trace_uprobe.c Thread-Topic: [PATCH 1/2] tracing: fix bad use of igrab in trace_uprobe.c Thread-Index: AQHT1t6qY2w++l1Em02GF9oER/KoaKQGjmAAgAAi9YA= Date: Wed, 18 Apr 2018 16:08:50 +0000 Message-ID: <6E88C284-7EEB-43EF-8C54-3DCB5F13124B@fb.com> References: <20180418062907.3210386-1-songliubraving@fb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3445.6.18) authentication-results: szeredi.hu; dkim=none (message not signed) header.d=none;szeredi.hu; dmarc=none action=none header.from=fb.com; x-originating-ip: [2620:10d:c090:180::1:db29] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR15MB1689;7:8TelGywGWPt5EHFk/oIhRnSeRB/MfjU10HdarJziAJv18RC06NSLOZKjhkBTXiKq4gs1eq0pn4XXECmWWyRmyRXeELOHTgMbmmc/kS+b2VNXfsTJzPMFdmB8MlMQrIPkIb/yHLLL/9Sh3l8FYsaAhd5xlFC1gA3xF96VevAgPK7GXpETqMVjOV7lCTRsrJoAdG162zwrIPV/crYIO6ESnssAM426zLjQCGFWCf0VagFdcqCVPK8jQYXZ61IngP2c;20:87Pm9dTVfloOKkI/nhELGfm/iJ5cEq7/xAxKEmwQhr5eyoNvcqY176GraT3onOhga88RoSFWW22+UN6dBQ8tYOl7EjJQRLVO7eoku9ZtX07lKz55upeVBhppTRxwYofp4MMAyr/R7D3vulVq8YVb5SsSfXuUdD4xY4uMd4g74Tw= x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DM5PR15MB1689; x-ms-traffictypediagnostic: DM5PR15MB1689: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(67672495146484)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231232)(11241501184)(944501327)(52105095)(3002001)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR15MB1689;BCL:0;PCL:0;RULEID:;SRVR:DM5PR15MB1689; x-forefront-prvs: 06469BCC91 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(39380400002)(39860400002)(376002)(53546011)(11346002)(86362001)(305945005)(6486002)(7736002)(81166006)(8676002)(76176011)(5660300001)(6916009)(25786009)(82746002)(6506007)(102836004)(59450400001)(4326008)(2616005)(33656002)(14454004)(476003)(36756003)(478600001)(6246003)(186003)(54906003)(50226002)(53936002)(6512007)(6116002)(6436002)(2906002)(446003)(5250100002)(83716003)(99286004)(8936002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR15MB1689;H:DM5PR15MB1548.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;MLV:sfv; x-microsoft-antispam-message-info: lUwwihtJ04JGy7TQ+F58iZ6sIQ1H5d6qsQB+2ZGxfJkGXGK/voZdCdEgHBtVYoTjkGnuR9HOeWv2DcVeLFxkJF7jLEFUyaVHYUvoKPEfgi4635Ng6Wwq8AdJ3XdcyLdiHj70i3jgJh68hISBT+JlZHpopu6RLocTfO9oqYr1wKfNtUo7ksn1VeWOQshGLXyC spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 4d699cc3-8f22-44c5-11ba-08d5a546ac8d X-MS-Exchange-CrossTenant-Network-Message-Id: 4d699cc3-8f22-44c5-11ba-08d5a546ac8d X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2018 16:08:50.2919 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1689 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_03:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Apr 18, 2018, at 7:03 AM, Miklos Szeredi wrote: >=20 > On Wed, Apr 18, 2018 at 8:29 AM, Song Liu wrote: >> As Miklos reported and suggested: >>=20 >> This pattern repeats two times in trace_uprobe.c and in >> kernel/events/core.c as well: >>=20 >> ret =3D kern_path(filename, LOOKUP_FOLLOW, &path); >> if (ret) >> goto fail_address_parse; >>=20 >> inode =3D igrab(d_inode(path.dentry)); >> path_put(&path); >>=20 >> And it's wrong. You can only hold a reference to the inode if you >> have an active ref to the superblock as well (which is normally >> through path.mnt) or holding s_umount. >>=20 >> This way unmounting the containing filesystem while the tracepoint is >> active will give you the "VFS: Busy inodes after unmount..." message >> and a crash when the inode is finally put. >>=20 >> Solution: store path instead of inode. >>=20 >> This patch fixes two instances in trace_uprobe.c. >>=20 >> Fixes: f3f096cfedf8 ("tracing: Provide trace events interface for uprobe= s") >> Fixes: 33ea4b24277b ("perf/core: Implement the 'perf_uprobe' PMU") >> Cc: Steven Rostedt >> Cc: Ingo Molnar >> Cc: Howard McLauchlan >> Cc: Josef Bacik >> Cc: Srikar Dronamraju >> Reported-by: Miklos Szeredi >> Signed-off-by: Song Liu >> --- >> kernel/trace/trace_uprobe.c | 42 ++++++++++++++-------------------------= --- >> 1 file changed, 14 insertions(+), 28 deletions(-) >>=20 >> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c >> index 0d450b4..80dfcdf 100644 >> --- a/kernel/trace/trace_uprobe.c >> +++ b/kernel/trace/trace_uprobe.c >> @@ -55,7 +55,7 @@ struct trace_uprobe { >> struct list_head list; >> struct trace_uprobe_filter filter; >> struct uprobe_consumer consumer; >> - struct inode *inode; >> + struct path path; >> char *filename; >> unsigned long offset; >> unsigned long nhit; >> @@ -289,7 +289,7 @@ static void free_trace_uprobe(struct trace_uprobe *t= u) >> for (i =3D 0; i < tu->tp.nr_args; i++) >> traceprobe_free_probe_arg(&tu->tp.args[i]); >>=20 >> - iput(tu->inode); >> + path_put(&tu->path); >> kfree(tu->tp.call.class->system); >> kfree(tu->tp.call.name); >> kfree(tu->filename); >> @@ -363,7 +363,6 @@ static int register_trace_uprobe(struct trace_uprobe= *tu) >> static int create_trace_uprobe(int argc, char **argv) >> { >> struct trace_uprobe *tu; >> - struct inode *inode; >> char *arg, *event, *group, *filename; >> char buf[MAX_EVENT_NAME_LEN]; >> struct path path; >> @@ -371,7 +370,6 @@ static int create_trace_uprobe(int argc, char **argv= ) >> bool is_delete, is_return; >> int i, ret; >>=20 >> - inode =3D NULL; >> ret =3D 0; >> is_delete =3D false; >> is_return =3D false; >> @@ -448,14 +446,6 @@ static int create_trace_uprobe(int argc, char **arg= v) >> if (ret) >> goto fail_address_parse; >>=20 >> - inode =3D igrab(d_inode(path.dentry)); >=20 > This is not against -linus tree. These patches are against tip/perf/core. I can also send version against=20 -linus tree.=20 >=20 >> - path_put(&path); >> - >> - if (!inode || !S_ISREG(inode->i_mode)) { >> - ret =3D -EINVAL; >> - goto fail_address_parse; >> - } >> - >> ret =3D kstrtoul(arg, 0, &offset); >> if (ret) >> goto fail_address_parse; >> @@ -490,7 +480,8 @@ static int create_trace_uprobe(int argc, char **argv= ) >> goto fail_address_parse; >> } >> tu->offset =3D offset; >> - tu->inode =3D inode; >> + tu->path.mnt =3D path.mnt; >> + tu->path.dentry =3D path.dentry; >=20 > You can just assign the whole structure. No need to mess with > individual members. >=20 > tu->path =3D path; Will fix in v2.=20 >=20 >> tu->filename =3D kstrdup(filename, GFP_KERNEL); >>=20 >> if (!tu->filename) { >> @@ -558,7 +549,7 @@ static int create_trace_uprobe(int argc, char **argv= ) >> return ret; >>=20 >> fail_address_parse: >> - iput(inode); >> + path_put(&path); >>=20 >> pr_info("Failed to parse address or file.\n"); >>=20 >> @@ -937,7 +928,8 @@ probe_event_enable(struct trace_uprobe *tu, struct t= race_event_file *file, >> goto err_flags; >>=20 >> tu->consumer.filter =3D filter; >> - ret =3D uprobe_register(tu->inode, tu->offset, &tu->consumer); >> + ret =3D uprobe_register(d_inode(tu->path.dentry), tu->offset, >> + &tu->consumer); >=20 > It is not entirely clear how the lifetime of uprobe relates to the > lifetime of trace_uprobe. Is the uprobe object never going to survive > its creator trace_uprobe object? >=20 > If that's the case, it warrants a comment. If that's not the case, > then the path would need to be passed to uprobe_resister() which would > need to obtain its own reference. trace_uprobe will not be freed before the uprobe object. trace_uprobe=20 holds reference to struct path (with path_get()).=20 >=20 >> if (ret) >> goto err_buffer; >>=20 >> @@ -981,7 +973,7 @@ probe_event_disable(struct trace_uprobe *tu, struct = trace_event_file *file) >>=20 >> WARN_ON(!uprobe_filter_is_empty(&tu->filter)); >>=20 >> - uprobe_unregister(tu->inode, tu->offset, &tu->consumer); >> + uprobe_unregister(d_inode(tu->path.dentry), tu->offset, &tu->con= sumer); >> tu->tp.flags &=3D file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE; >>=20 >> uprobe_buffer_disable(); >> @@ -1056,7 +1048,8 @@ static int uprobe_perf_close(struct trace_uprobe *= tu, struct perf_event *event) >> write_unlock(&tu->filter.rwlock); >>=20 >> if (!done) >> - return uprobe_apply(tu->inode, tu->offset, &tu->consumer= , false); >> + return uprobe_apply(d_inode(tu->path.dentry), tu->offset= , >> + &tu->consumer, false); >>=20 >> return 0; >> } >> @@ -1088,7 +1081,8 @@ static int uprobe_perf_open(struct trace_uprobe *t= u, struct perf_event *event) >>=20 >> err =3D 0; >> if (!done) { >> - err =3D uprobe_apply(tu->inode, tu->offset, &tu->consume= r, true); >> + err =3D uprobe_apply(d_inode(tu->path.dentry), >> + tu->offset, &tu->consumer, true); >> if (err) >> uprobe_perf_close(tu, event); >> } >> @@ -1352,7 +1346,6 @@ struct trace_event_call * >> create_local_trace_uprobe(char *name, unsigned long offs, bool is_return= ) >> { >> struct trace_uprobe *tu; >> - struct inode *inode; >> struct path path; >> int ret; >>=20 >> @@ -1360,14 +1353,6 @@ create_local_trace_uprobe(char *name, unsigned lo= ng offs, bool is_return) >> if (ret) >> return ERR_PTR(ret); >>=20 >> - inode =3D igrab(d_inode(path.dentry)); >> - path_put(&path); >> - >> - if (!inode || !S_ISREG(inode->i_mode)) { >> - iput(inode); >> - return ERR_PTR(-EINVAL); >> - } >> - >> /* >> * local trace_kprobes are not added to probe_list, so they are n= ever >> * searched in find_trace_kprobe(). Therefore, there is no concer= n of >> @@ -1383,7 +1368,8 @@ create_local_trace_uprobe(char *name, unsigned lon= g offs, bool is_return) >> } >>=20 >> tu->offset =3D offs; >> - tu->inode =3D inode; >> + tu->path.mnt =3D path.mnt; >> + tu->path.dentry =3D path.dentry; >=20 > tu->path =3D path >=20 >=20 >> tu->filename =3D kstrdup(name, GFP_KERNEL); >> init_trace_event_call(tu, &tu->tp.call); >>=20 >> -- >> 2.9.5 >>=20