Received: by 10.213.65.68 with SMTP id h4csp2118005imn; Sun, 8 Apr 2018 20:09:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/bhn+kBAN1ZSsMPLG+0HRfw5fI+N5wNQW2r598ouGWIGVpsWR/ts5GeknwHR59fVE1+c9a X-Received: by 2002:a17:902:8348:: with SMTP id z8-v6mr36276209pln.311.1523243353750; Sun, 08 Apr 2018 20:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243353; cv=none; d=google.com; s=arc-20160816; b=bofAgDiG7K6Qo+3mGgSm7NLTOh3vciGMZSCssF10aridijodxCu17Ape6fuiEM2EqD eQ/SnCpzaMrl1/mkKPXXWy9L8NaKNBwdqwC8OnNasaZ43OXQJ6opVaeZyJ9Z+bCwzBTE 6co7kjqP+6ph7LfsLzK9WlbYWubSGVxqou5keelEkcek7inDhlJwtxQsEnIWRcyAUlRr 25pz8sDNofV6iZoAvOL4pPSLV8IsSGtDZmTSRwW/oIHkmnUg4adHUHtQWmie+SvdjB3K bVq+t3Ex5X0BfSZnWgRAv1+Sf/1/LvduXLPA+eWkY/Mpa+ssTgYd7lCDus1rshVE1gTT hrPw== 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=DMfKsnVftIHud7tfCm4BTI3RJlnZ6ofE5ehlbMPi18E=; b=Od1/y7e8EIWQPmFtfXzC0R6KPVUcg48CF8aw9bYDfnd0dTSi0VUiAcoERWb5Xs6Vjq GWObK4YpBlp0jk+cvLlEiCrdYU/kUBEzlw4JCBmLpnwVA9OnF/C1tOpVPN5L+gGCuEtS 3Zlu/gCThKkltbL93KE186dKR+dopomMpYBRG7RRruvf9HUQbQu2sCnEbpGU9dmO7s80 OFGTDs4h/Y2waSWVkXBlrShsF7nI8cp2l+A4uMdx+JJSn5AkOe5Odb1W4gbJj0BswDNG 9CXc37eDhI95dmdQwUdAFuSgU1UY3kcqlZJF/drqICme0hINkpON03cPVlwNFxCAdFWd an8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=e0pxC2JX; 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 q12si10628779pgs.55.2018.04.08.20.08.36; Sun, 08 Apr 2018 20:09:13 -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=@microsoft.com header.s=selector1 header.b=e0pxC2JX; 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 S933091AbeDICZD (ORCPT + 99 others); Sun, 8 Apr 2018 22:25:03 -0400 Received: from mail-by2nam03on0120.outbound.protection.outlook.com ([104.47.42.120]:61603 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755954AbeDIA3P (ORCPT ); Sun, 8 Apr 2018 20:29:15 -0400 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=DMfKsnVftIHud7tfCm4BTI3RJlnZ6ofE5ehlbMPi18E=; b=e0pxC2JXMNPT8gApKdXLwEA7Hzk1/W21pw6VRTNS/Z8scAtTCgM2H5DLsa9hoovFacKDA67sFHUogBWMYenUb7xRkDfb2diUgDvDI62BEb1466kMrKQ9d9cAJrD5Xa7qbYdeuHQWOFxZ6azeSB9PL87CoEEym/sCWeQ0dHaPqTM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0967.namprd21.prod.outlook.com (52.132.133.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:29:13 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:29:13 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Takashi Iwai , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 098/293] ALSA: hda: Fix potential race at unregistration and unsol events Thread-Topic: [PATCH AUTOSEL for 4.9 098/293] ALSA: hda: Fix potential race at unregistration and unsol events Thread-Index: AQHTz5kUlHccKXWS9E6eL5/8GEzZ6w== Date: Mon, 9 Apr 2018 00:24:10 +0000 Message-ID: <20180409002239.163177-98-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0967;7:ik4lNTgzWKBBHzjMWH6bQUhjZaysUMB/ylHF6tJ5J39yKg8NjJiQqKdDut0pl47H8PIYaZmrH4vaFeVh3esEJ4/zZccafZAjuPdR4tDHuPBmjnAi2xdeJuw1j2lngerCJtKdcQV+OvKMpA8IfAjkhtb/Cx0b9moZXloR9PzE64OopitNdWkNcM4kv9n9gAfNJiTJEBG/5RD2iMFeqvxgV751Kqu5zR5RoPewWbKckLDL7cfwFH3zTP4FT1xmLLDK;20:xIVkpTOkpRfeojG5f6QJdkwaYdtj4ywpT2NF8q2bEJmVbGq/TPZT3uWVEDgA+D/IvDxC+zxpSR5zpJE0oYMF/RAM6NsmwHtSDFsupHMhqFXiywMYIRlhOLh7UeTDu5BBsFFM+DY4ZH9iBiJnoswkBLrYhOb8rQofjuC2R87Mn4I= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 1e8af3a5-2273-4d04-a474-08d59db0eb63 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0967; x-ms-traffictypediagnostic: DM5PR2101MB0967: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(191636701735510)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0967;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0967; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(376002)(39380400002)(346002)(199004)(189003)(6506007)(486006)(575784001)(86362001)(14454004)(59450400001)(68736007)(102836004)(99286004)(26005)(3846002)(6116002)(186003)(476003)(2616005)(1076002)(3280700002)(86612001)(72206003)(966005)(4326008)(446003)(54906003)(76176011)(11346002)(2906002)(22452003)(3660700001)(110136005)(97736004)(316002)(5660300001)(478600001)(8676002)(6512007)(6306002)(8936002)(107886003)(6486002)(53936002)(81166006)(36756003)(81156014)(10290500003)(6436002)(10090500001)(25786009)(66066001)(106356001)(305945005)(7736002)(2501003)(5250100002)(105586002)(2900100001)(22906009)(217873001)(15866825006);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0967;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ++pUFSm1VvaJIuavLlcOhzB4fwiHsQsQdUAKgiZC0JCCxphTsCgBg9fpD5gVO6Y4aP4x4odV7kIWaCZ+BAQSYM8NqxVz4Mb1xM7vp4cx5hF6tALZONOFkprveRaAbPaCDkjFOV9ja2TV3PQKISylhM2Oss536GSf8bUDxy1TmQjtSYbSShjOlRfjRGzeSjWWZq2QFjQAhE5kd1qy1el+KyGlmh/ak7vIa7zyKUp7n1Gr79cZclqJ3WIwyMyvevo8M7tHglfPyPdsDbwkcJ0UQpaE/nU4QlyugBQv7ZBUx6oyh/tsuNrEdQ6F9yt89Rf/fjGu+aGZ1KCVFntpeRPU94W2UnmrfFOWmM79wp4tWDMyloCPZ5MNt1dHocJ7vhgRkhp4SZkEkUT3pzWEeYwpSaffGMZCWOZXEWCSoam1Khg= 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: 1e8af3a5-2273-4d04-a474-08d59db0eb63 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:10.2843 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0967 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit eb8d0eaaf84b0398533a7c091a0b65663f2fd7ea ] When the codec device is unregistered / freed, it may release the resource while being used in an unsolicited event like the jack detection work. This leads to use-after-free. The fix here is to unregister the device at first, i.e. removing the codec from the list, then flushing the pending works to assure that all unsol events are gone. After this point, we're free from accessing the codec via unsol events, thus can release the resources gracefully. The issue was spotted originally by Intel CI, but it couldn't be reproduced reliably by its nature. So let's hope this fix really addresses the whole issues. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=3D196045 Reported-by: Martin Peres Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/hda/hdac_bus.c | 1 + sound/hda/hdac_device.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c index 0e81ea89a596..714a51721a31 100644 --- a/sound/hda/hdac_bus.c +++ b/sound/hda/hdac_bus.c @@ -212,5 +212,6 @@ void snd_hdac_bus_remove_device(struct hdac_bus *bus, bus->caddr_tbl[codec->addr] =3D NULL; clear_bit(codec->addr, &bus->codec_powered); bus->num_codecs--; + flush_work(&bus->unsol_work); } EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device); diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index 03c9872c31cf..19deb306facb 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -159,6 +159,7 @@ void snd_hdac_device_unregister(struct hdac_device *cod= ec) if (device_is_registered(&codec->dev)) { hda_widget_sysfs_exit(codec); device_del(&codec->dev); + snd_hdac_bus_remove_device(codec->bus, codec); } } EXPORT_SYMBOL_GPL(snd_hdac_device_unregister); --=20 2.15.1