Received: by 10.223.176.46 with SMTP id f43csp275681wra; Tue, 23 Jan 2018 20:51:21 -0800 (PST) X-Google-Smtp-Source: AH8x224k5x0cJGbxkxmqeGUNmpLx5X9KrMScXUL7ut/Tij4M5SkN907BnYuTn3aYlSv0ym0OYUBL X-Received: by 2002:a17:902:650e:: with SMTP id b14-v6mr6938204plk.451.1516769481889; Tue, 23 Jan 2018 20:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769481; cv=none; d=google.com; s=arc-20160816; b=V5vkr5rXepAC3pCUdEml4zeEyROI42vm8MQXRh9JmssZ2KVde+wqwNrVvIemrCFo8O KSjX8sWncc3WP8ZTUqBzBkFokAKGzXvBqW0uJN80bUBz5jOv3DJld6a4hzUzD+y8i6vg yNCsjR034LDjFSEiZOj/oD3F8zyzAg/DTFGQoz4U5U29gQDdJeQxWWJi7DJSKxEu9v4N jfBrpInx7RnWMV9Nn6G88WH+aRuBpjoaXZP55IXxxeSLhsiK5ZSJxAR0cixpGAZUBr+Z w57qjkP44zTdhRTG7hwiej1lvPumu0oeqlTOJUuWp2qeK7u3nXdNY4unslswz3hI+2wO whFQ== 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 :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5ViHTw3cXqmgh9s7RQO+aGiwVQaW5WRKO5289hrX418=; b=GYnEiEx/JxIVp3NDoH0D4+yk1ranbaafqdYVdEc30KISI4fLK5OTPkh3PILMO+aSlD 0dwGJBEz3Ew0VGPeLYn2RefidK7hCFauxq6BrjELW2BJv9xDXV81QgOZsn+ZXNCaTyks QsDwahFfHVCjCInA1r0DxA9n/yaWsiEW07mc2ZfHkTINE+e5vfhZkALvfCTzZKndLtjM 1dop6E3pM0L9a+8Lie1NQkMpehXLK8iIpPsLc0V5xD/kxSZQVFxmh2bwPa5AIcJPNMLG NC/4TJbJBdjwHiJkhyl8GIdSm+X6jOy22IukSulQEFSj1V7+eTlPujhCZLW8OWbpJycJ 9iSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BnqyLY1n; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si5097055pgv.685.2018.01.23.20.51.08; Tue, 23 Jan 2018 20:51:21 -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=@microsoft.com header.s=selector1 header.b=BnqyLY1n; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932486AbeAXEQF (ORCPT + 99 others); Tue, 23 Jan 2018 23:16:05 -0500 Received: from mail-sn1nam01on0105.outbound.protection.outlook.com ([104.47.32.105]:55328 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932246AbeAXEPz (ORCPT ); Tue, 23 Jan 2018 23:15:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5ViHTw3cXqmgh9s7RQO+aGiwVQaW5WRKO5289hrX418=; b=BnqyLY1n7JIPdwyKhIqSihwl4PgOkIeT3t0ng8MMnJCv/WcnqfcOeLNM+aeFgdtk+4ov3CDqtLLLfXlwNJaSEZybxy8AEsFvgL+qB5BxhqwEoF3zqWKMLtDA86MVrxxBbFfmLMkRh/H5zMIi8dlGNT0aZ7FEldYOJeBVSQQNH9Q= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.0; Wed, 24 Jan 2018 04:15:53 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:52 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Vasily Averin , "J . Bruce Fields" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 061/100] race of lockd inetaddr notifiers vs nlmsvc_rqst change Thread-Topic: [PATCH AUTOSEL for 4.14 061/100] race of lockd inetaddr notifiers vs nlmsvc_rqst change Thread-Index: AQHTlMnjH+Vk2IpxikmcJgfUYnQemg== Date: Wed, 24 Jan 2018 04:14:55 +0000 Message-ID: <20180124041414.32065-61-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:+hnXtL7BlirD5Q75fBnYCAdF7uC4Dd+2d3kqnSUp82WG9mI/v4AgZ7Z4SkuwPxrOhAXFFM9pxDVweimDdt1Hl68+8yw5o6Un3xiJ38ip7uwGhunS1h5ncPXLehE24Yj6LfqMe2irdlRnkvYbsRZKP121VE/6YFtGG2ZW/lYu3cujTd9lzJXg+YaWsjY2SOADvptD7PjsZ9Or6n/drbrLMAq7oGjG16ayh5PN0/hquwSYGzwqYAG+8llhxod9QImQ x-ms-office365-filtering-correlation-id: f88ca937-3615-41fa-3604-08d562e12887 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(376002)(366004)(39860400002)(346002)(199004)(189003)(478600001)(106356001)(6512007)(53936002)(2900100001)(36756003)(102836004)(2950100002)(2501003)(10290500003)(97736004)(14454004)(81166006)(72206003)(8936002)(6486002)(1076002)(10090500001)(6346003)(26005)(54906003)(4326008)(76176011)(99286004)(86362001)(3660700001)(105586002)(6116002)(8676002)(68736007)(22452003)(66066001)(25786009)(6506007)(5660300001)(305945005)(59450400001)(7736002)(3280700002)(5250100002)(2906002)(107886003)(86612001)(6436002)(316002)(81156014)(3846002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: DwvKT4DOt41//fD2rxf9VUyIhqnmQ53lXQbrBvI7IBqUTzNA8tBdT7wZPBY2DZNXuV6K6KSiv4JCu43Oy+DjIA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f88ca937-3615-41fa-3604-08d562e12887 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:55.8481 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Averin [ Upstream commit 6b18dd1c03e07262ea0866084856b2a3c5ba8d09 ] lockd_inet[6]addr_event use nlmsvc_rqst without taken nlmsvc_mutex, nlmsvc_rqst can be changed during execution of notifiers and crash the host= . Patch enables access to nlmsvc_rqst only when it was correctly initialized and delays its cleanup until notifiers are no longer in use. Note that nlmsvc_rqst can be temporally set to ERR_PTR, so the "if (nlmsvc_rqst)" check in notifiers is insufficient on its own. Signed-off-by: Vasily Averin Tested-by: Scott Mayhew Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin --- fs/lockd/svc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index 45e96549ebd2..809cbccbad28 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c @@ -57,6 +57,9 @@ static struct task_struct *nlmsvc_task; static struct svc_rqst *nlmsvc_rqst; unsigned long nlmsvc_timeout; =20 +atomic_t nlm_ntf_refcnt =3D ATOMIC_INIT(0); +DECLARE_WAIT_QUEUE_HEAD(nlm_ntf_wq); + unsigned int lockd_net_id; =20 /* @@ -292,7 +295,8 @@ static int lockd_inetaddr_event(struct notifier_block *= this, struct in_ifaddr *ifa =3D (struct in_ifaddr *)ptr; struct sockaddr_in sin; =20 - if (event !=3D NETDEV_DOWN) + if ((event !=3D NETDEV_DOWN) || + !atomic_inc_not_zero(&nlm_ntf_refcnt)) goto out; =20 if (nlmsvc_rqst) { @@ -303,6 +307,8 @@ static int lockd_inetaddr_event(struct notifier_block *= this, svc_age_temp_xprts_now(nlmsvc_rqst->rq_server, (struct sockaddr *)&sin); } + atomic_dec(&nlm_ntf_refcnt); + wake_up(&nlm_ntf_wq); =20 out: return NOTIFY_DONE; @@ -319,7 +325,8 @@ static int lockd_inet6addr_event(struct notifier_block = *this, struct inet6_ifaddr *ifa =3D (struct inet6_ifaddr *)ptr; struct sockaddr_in6 sin6; =20 - if (event !=3D NETDEV_DOWN) + if ((event !=3D NETDEV_DOWN) || + !atomic_inc_not_zero(&nlm_ntf_refcnt)) goto out; =20 if (nlmsvc_rqst) { @@ -331,6 +338,8 @@ static int lockd_inet6addr_event(struct notifier_block = *this, svc_age_temp_xprts_now(nlmsvc_rqst->rq_server, (struct sockaddr *)&sin6); } + atomic_dec(&nlm_ntf_refcnt); + wake_up(&nlm_ntf_wq); =20 out: return NOTIFY_DONE; @@ -347,10 +356,12 @@ static void lockd_unregister_notifiers(void) #if IS_ENABLED(CONFIG_IPV6) unregister_inet6addr_notifier(&lockd_inet6addr_notifier); #endif + wait_event(nlm_ntf_wq, atomic_read(&nlm_ntf_refcnt) =3D=3D 0); } =20 static void lockd_svc_exit_thread(void) { + atomic_dec(&nlm_ntf_refcnt); lockd_unregister_notifiers(); svc_exit_thread(nlmsvc_rqst); } @@ -375,6 +386,7 @@ static int lockd_start_svc(struct svc_serv *serv) goto out_rqst; } =20 + atomic_inc(&nlm_ntf_refcnt); svc_sock_update_bufs(serv); serv->sv_maxconn =3D nlm_max_connections; =20 --=20 2.11.0