Message ID | TYCP286MB2323950197F60FC3473123B7CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1758634wru; Sun, 30 Oct 2022 04:47:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM58gxyUK+J1LkQfQ9WOK9KsAD+5gYEBNhClZNb7L1E0zUvSzxlCm8HxE5RqHDqQ1xcO8Rve X-Received: by 2002:a05:6402:40c7:b0:461:ecdb:1c41 with SMTP id z7-20020a05640240c700b00461ecdb1c41mr8226230edb.288.1667130455759; Sun, 30 Oct 2022 04:47:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667130455; cv=pass; d=google.com; s=arc-20160816; b=RoqwQCQzJHDEWBn+0FM6F3w9X4u4MKEMKrMHGnTc690x1HwIojsoop07nLArZOspup b+Fb8hj+XMLNlaf1G1xK/oFHTYayuRriP77NoiXLtjdQ0ot6cNQy2wvpRAjfO3uN6lMN y+hQnffWVAkVnjFBWqiNKyf0rh2DZXp32VDTQig1Hu3rIsngqenqkMPIMoxUDFSh0n5S nAB552vZuWwr4gLFIGVz+CoA8zjp029pgzimEIIKUf+FSuGn+sF+wl64iKqiFlxw+5ND dN6NSmc6lgEc2vz5jhQ5JGdMrHA28nSJOGpnXOvvda3hck35Gxegv+7W/YaW+AcjLTyk ukkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=P9pKEVVkoZvxLfyW1TdBXU/d5n/MTFidVzDZ/IMMcFmX6uLqj0taoV+iWI8myCp5W7 Ld1TPKKkgMMHwHP30yG4kO3vcmqOLj+AAtwghkriQhJlPqvG2Dks10AzmJTELd9iIJCc qF4Me+TXLiIPSsQX07I9O7ZeJZkdG4p+ZPhGvbNPoXBm8pxe1GecjqCvm1SoMsJHlrxU QRMG6HHW68cH7XnbhJCNLnlN5yTeZwdTgb0mq6Xcpj6yBJXbdBUoK7eau9VkxVvl/UNJ YhrziJRZaCrMOf2PTNY0cU44DZRJrYDQLdaQL9zSCcPMxbZVrdVz7jJqfV1S49dVDU8n 2YYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=dD6Cda0K; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg19-20020a170907971300b007804f3dafbesi5215479ejc.587.2022.10.30.04.47.12; Sun, 30 Oct 2022 04:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=dD6Cda0K; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbiJ3LhW (ORCPT <rfc822;paulgraves1991@gmail.com> + 99 others); Sun, 30 Oct 2022 07:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiJ3LhU (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 30 Oct 2022 07:37:20 -0400 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2027.outbound.protection.outlook.com [40.92.98.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6576AE55; Sun, 30 Oct 2022 04:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuTBaEmzOCxjLSJWXzLCCJkrgduIhexB/CjDrjGN4IcDzGO4EQsa6hPlzqXyKIfwDOB4EjY8ALWLvkdIksEzKEU1dEwNhl+mKvm/Oz3uOSbomC+EeXvdweGPmpWnyxOFbAFM25rpQwRnJUZ6yiXJNfg3obVNVX0ESbP/+3F0lssnC8gs8DtprlClQ2vx5ERiER2xWPY9S6fz/EB/4vtAJIm9LrGBcPurOX0+usKII0g4shsBjwj/fUtou9AcTPKTUR4vK/+DVAzzp0ZU/9Chr7Hnx289r9H4oIMYEVSPeyKZNx0tuJRAwMIvjW5khZCOytc7OufNr1DrrS/jic8o/w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=fVIAlrOXPdSef1NDonDUPfCAVVmFTQAC7FeBD0abt2pGz29C6YOJbbuRFR727HaUUEsDrY7J9DJUjayc+dexDpvdhkr7rkOnWkICf+VUr8eUMkR1KOufXaR7UlTnhha3HfxZIiGffveoXcXIJIL9k6MEnDkYADVRma2M1YmIEx+9Y3Zhn65mTnrit3OVBci/xBCDSi9uHtdNv65OJYlpdGMnH+Q3+Fq1o7CWIevlKuU9cMy97U2wkIurcVDofX9MlS/rq5+Xh227BxE9cIGb+kVNjOmF7XFyEZ5vOadBzZxUGsk0CycAt6FtfiGAXWd1cilfqgym667tar9KR5hGxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=svsL4S9jfk3q5oc4G6+CXyigCp88sv9APcA7xWoQvzk=; b=dD6Cda0KIGFIL+Rpuh60/dgKbd/WmEZ9DF2ULWpJGXK99mUl4HHGEnJKnScSalvcK2bpVXXw96HnePe0i7qIAmHYvg7ivGCAU2on91qH1kVbnBNd6ntIkwfabAKeCOLF4895avFat2jzXLihTiQqgOuHbn7bn6rlL67eTaVQ8lz15TL0oT/ZBsxATdl+c4JXQWL/o3Ln9XiHfHpYbXh2jCWd72XGzTXawGNHcIw/SBRkBDMFJimM2jrKsg7Z3JWQIOeJ/bx6kCRMU3RU9AGhaQfDY2nAYSC+FqF3dp5YOyaEaytDzHPDqC4st29IZPilKZYkjW33XmaqN532BXUZBQ== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OS3P286MB2709.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1fc::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Sun, 30 Oct 2022 11:37:12 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5%7]) with mapi id 15.20.5769.018; Sun, 30 Oct 2022 11:37:12 +0000 From: Dawei Li <set_pte_at@outlook.com> To: sumit.semwal@linaro.org, christian.koenig@amd.com Cc: benjamin.gaignard@collabora.com, lmark@codeaurora.org, labbott@redhat.com, Brian.Starkey@arm.com, jstultz@google.com, afd@ti.com, sspatil@android.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Dawei Li <set_pte_at@outlook.com> Subject: [PATCH] dma-buf: fix racing conflict of dma_heap_add() Date: Sun, 30 Oct 2022 19:37:00 +0800 Message-ID: <TYCP286MB2323950197F60FC3473123B7CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [Um6xlQbCyYoT19WyxqearVE+xI9G5zJia2KmZRKIW1k=] X-ClientProxiedBy: TY1PR01CA0184.jpnprd01.prod.outlook.com (2603:1096:403::14) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221030113700.3300-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OS3P286MB2709:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cdf1d64-4620-4054-bfbc-08daba6b15da X-MS-Exchange-SLBlob-MailProps: 70qbaZjg4mv1OqsmyvwVkO5pclI01FVpovJWLvgsAQ8XASbU4UOFaqFZL/PS2XbnOslcIt6Wz0uOSrOC9MGcWkJXC3bdrn+h519oQNbJEaL8MJvXBIOdsh89jAQfeDMMTP5LypWXzKXsx8nlrc/aMGMQfzEhe+Ws6WwLSAnvj0I7dCqywraaYzSvSCw7SxCd733Zr9JOCQPxgKAUs/6Rksg2iItWHErYYFlyGYezzUOKi/inmm0bxARf2o2Rz1/E47PEK37FbCpY8CJBfgqDPLx4nEfEhT6s3t7MW5sfqrS9qJc3wlFMRsDElf355N0PuFG0d/lsg1dFBeTDwXYGm1BcjdCgdBdkmWpgtd0EMxd5T2EXL6/FRB6dfaubfQXoceHEbgRoklqTeOddYl/42zOjEyROZcfZZN254tsOJB7MTyH/XHU0eOTZ1I0d92ANjy92T/UapdclR/SN6T/PgYMRv0XFcB7YQg3Ss/PF6yWMioH/qaCcJrBHqa3nSovpVSlk7Frm8qyvrI7/A+Ip0rSY2JKSJEh4NvycrQVplHqVj8S+/JCMacYgvCJpZSWUp5S3N8UYQuLXjvau2u+gQ5oS1PwXUXEnjdTAjpAkpt/8yPjvh1dQFO+SkAgDDulz9f29ZCremVJX4ghP/k0aF41fQin0jP/tSku/H0mD4TnUKxi8RwwrmnZYdmmf65bPaAFRvfkba30wCx2OhTJvrMcQkN45LyatOaO55nrsaF7w8Xqmb7DOfg== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: npwPx69ixe1sxoMNDYfYUA7fZtfrSfxK62GQHUd5RopMghybxACdtqy/AS5vsojqtR0RiXMKW4dSNVaRf+QcmHCM3b/acDmxYIdCb9bOhFSyRGRVMJRiCDTdPvBzONPFtKmjE72Q0+PvofWBbuq7+D7o4Fxu1TXsqsWU8ER158ucWBZqR8njxcJOssosbuX7eqZYGKaRXob+PjlSJSFVEvMimh4xh2tPuCblIE1JVqO2mWEg6wkJqH+iOJFJUKbe5/5UFVDFVYrntdhnS1Vj9AXcp2bLLmzjQDWs6jYtO/dTukU67NJkGKPKNZAs30FTW6DYpsn2/wAPuGMHYPWJ1tPOvJwBPq0ZCO5puoKtSzYuPm8EWzZJu/2/plLVh6kwZY5BvRYav9jAaP+8IPZ7cqdvNbm0W6WYCCePbND3wVb7NOCTfSfedOJumn619c8Q9A+0/PfUDY8iKEPTjXp6dc+5nvCkwg/pgEzDY/ZePJNoEPTiHkoJMbtZhwOVnhCl848M2HT6Iow+8C+dUFgB7MiYbeScJHPidJbG8vVZE1YLfcz8ZcNsfaTCiUJrOcfavi/UFVSp7ti4XhDdgzsaa3v1O/uEh3GBo3wr55cqThARCOXpSdAO3mlm5korTby3aHo1zzf/QZfHchiTM2O/N3019oO7Ql+FHV8US4L8xutCFi9hsintRYFe6LxYXSAk X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange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UaGWq4Cm1LMALyeVcJ0Ex7n9S2XXXLdis0NI48In9Dhb+qC+gS0/JOoz7WeRq56KLw0uI/TsXEuPtVtUlkT3ZFPYMIBqNwLA0q84nfjeME6v4d9DrfF8GTyWUuvQHtc/7G9Tk0iR0gMFN/SivhOHCsTQlKLtqGpPl0anElXMf+ZurA70b3sqwhXjs0LVB+1EX3lRnTuktl+UcbfH6YqawdQnV61zricy62yny3tSL+39j8A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cdf1d64-4620-4054-bfbc-08daba6b15da X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2022 11:37:12.0082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2709 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748112984891373743?= X-GMAIL-MSGID: =?utf-8?q?1748112984891373743?= |
Series |
dma-buf: fix racing conflict of dma_heap_add()
|
|
Commit Message
Dawei Li
Oct. 30, 2022, 11:37 a.m. UTC
Racing conflict could be:
task A task B
list_for_each_entry
strcmp(h->name))
list_for_each_entry
strcmp(h->name)
kzalloc kzalloc
...... .....
device_create device_create
list_add
list_add
The root cause is that task B has no idea about the fact someone
else(A) has inserted heap with same name when it calls list_add,
so a potential collision occurs.
Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework")
base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7
Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
drivers/dma-buf/dma-heap.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On 10/30/22 6:37 AM, Dawei Li wrote: > Racing conflict could be: > task A task B > list_for_each_entry > strcmp(h->name)) > list_for_each_entry > strcmp(h->name) > kzalloc kzalloc > ...... ..... > device_create device_create > list_add > list_add > > The root cause is that task B has no idea about the fact someone > else(A) has inserted heap with same name when it calls list_add, > so a potential collision occurs. > > Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework") > > base-commit: 447fb14bf07905b880c9ed1ea92c53d6dd0649d7 > > Signed-off-by: Dawei Li <set_pte_at@outlook.com> > --- > drivers/dma-buf/dma-heap.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c > index 8f5848aa144f..ff44c2777b04 100644 > --- a/drivers/dma-buf/dma-heap.c > +++ b/drivers/dma-buf/dma-heap.c > @@ -243,11 +243,12 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > return ERR_PTR(-EINVAL); > } > } > - mutex_unlock(&heap_list_lock); > > heap = kzalloc(sizeof(*heap), GFP_KERNEL); > - if (!heap) > + if (!heap) { > + mutex_unlock(&heap_list_lock); > return ERR_PTR(-ENOMEM); > + } > > heap->name = exp_info->name; > heap->ops = exp_info->ops; > @@ -284,7 +285,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > goto err2; > } > /* Add heap to the list */ > - mutex_lock(&heap_list_lock); Good catch! In general I'd like to hold locks for as short a time as possible and only bracket the lock associated structure (heap_list). How about we move the duplicate name check to down here so they are both inside this one locked section here. I know this will mean we take a longer unwind error path if the names are duplicated, but that should be rare and this will keep all heap_list accesses together. Thanks, Andrew > list_add(&heap->list, &heap_list); > mutex_unlock(&heap_list_lock); > > @@ -296,6 +296,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) > xa_erase(&dma_heap_minors, minor); > err0: > kfree(heap); > + mutex_unlock(&heap_list_lock); > return err_ret; > } >
diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 8f5848aa144f..ff44c2777b04 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -243,11 +243,12 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) return ERR_PTR(-EINVAL); } } - mutex_unlock(&heap_list_lock); heap = kzalloc(sizeof(*heap), GFP_KERNEL); - if (!heap) + if (!heap) { + mutex_unlock(&heap_list_lock); return ERR_PTR(-ENOMEM); + } heap->name = exp_info->name; heap->ops = exp_info->ops; @@ -284,7 +285,6 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) goto err2; } /* Add heap to the list */ - mutex_lock(&heap_list_lock); list_add(&heap->list, &heap_list); mutex_unlock(&heap_list_lock); @@ -296,6 +296,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) xa_erase(&dma_heap_minors, minor); err0: kfree(heap); + mutex_unlock(&heap_list_lock); return err_ret; }