Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7304616rwr; Wed, 10 May 2023 06:42:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a89ReN5gCzhFpxdREPI6nNCjLR1XA3lS8hWbPDBpzu61lv0G5stgN4ASvDiZY1fMHT2bq X-Received: by 2002:a05:6a00:17a5:b0:63b:1708:10aa with SMTP id s37-20020a056a0017a500b0063b170810aamr26532296pfg.34.1683726174396; Wed, 10 May 2023 06:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683726174; cv=none; d=google.com; s=arc-20160816; b=mnPdtnamA+ESlBLx93Tc4C0mglz/k6tD93azW9cmz0YcZgLQBQEoCscJDZDr6hnt0t szNLBTVrSAj8OAWqjGAv8+1xmoZ908nIFE/dlWlc0+scG67yKSMGGvcEnmJp4xypRdi6 cLmgG9b4xiJbjGNbCpqFcmnoEzGasvwphJvurbIz7M4xOgX0P6LdBNGeAahiKjX3t9XU 2n6euT8h/e6db2ijRrwjugwDrBILXYdY/yLzfx+cOce4gD+lQK8Gt2yPPWx0/Ec99/JV 03ML8JEZE/BjCJQvGQp4oUvc2/LFyI5K6/ihaOKtdl41kAusvbrpzNGSmM/GO0x66/j+ n8Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=c4F1xEjgxHDFVmvNQQSBfbbHaJRpES4qNBmdpH4mq5I=; b=vgk0pAH4fCg7Xpp7jsKi30cDAGRgcQc8b6H9hJXyNX8bYZ3t00FLcmBPDNVW6SxFDj pN5bTNXTdIKIYicnpHzNnzBB39wtNY6Tlcxr+nf1YJBBW6O/ZSTelvcqBppu81a9rM9i CrGU14jSukZ9knPqHhswFFc7sTyceNqIVkzanMBJcNAyLfdAuu5vJ5/Cr9R5uC/h7N8M PYUIUnrvwxxCMi7ETUxXfCQ9wA+9qHPKBjpwVVew6LI/d2kCLH0StQquZccGLvBX/coN wz7IIMXXzP7AIL5TJy7iD4sl7eOt85yx6fiI0OVCQejVWX4IrerkOhlFnLSrRgUl+0rN wdhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PMx8eQdE; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a639314000000b005138c1f1fccsi4029600pge.31.2023.05.10.06.42.38; Wed, 10 May 2023 06:42:54 -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=@kernel.org header.s=k20201202 header.b=PMx8eQdE; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237153AbjEJNf1 (ORCPT + 99 others); Wed, 10 May 2023 09:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237147AbjEJNfZ (ORCPT ); Wed, 10 May 2023 09:35:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFD661B2; Wed, 10 May 2023 06:35:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CE1206115D; Wed, 10 May 2023 13:35:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30192C433EF; Wed, 10 May 2023 13:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683725716; bh=rvr/wktaXUQdbZyUNVM6L1zlwE98uUFOn7vnuHwakgo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PMx8eQdEgir55rrWh8cmLsVWjb9ETd1apymlvypdlcEhNjP3uJuBNRKo/V6+VQYaN VjuHIT/udJGZml2gcO1Gr0UDifQWm6Lk9M0s84e8by3b5YOSXT0U5W3s4e1wp4PMDP AJo7UiSVXIjj0bikAQeVvmKq3sFL3+6FTm/hCm4wUdLtFoEMiiDzMkF/ljGQ+7DmJx 6I6eBDMokdyiK9rFpMu//KNlNWmZlcQnIzIvsfnK6g3yv2J1kRzwlKQYSX/T6Pzpcj wI8jfA8VHThRRWzpvL5pPoyDQzt+qsGu8Hrxq3doy3g5fuSBxX4iJuubz4cBSbx2oa x2BQBfUzygPfw== Date: Wed, 10 May 2023 14:35:11 +0100 From: Lee Jones To: Dan Carpenter Cc: Jassi Brar , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] mailbox: mailbox-test: fix a locking issue in mbox_test_message_write() Message-ID: <20230510133511.GB8963@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org Good catch, thanks Dan. On Fri, 05 May 2023, Dan Carpenter wrote: > There was a bug where this code forgot to unlock the tdev->mutex if the > kzalloc() failed. Fix this issue, by moving the allocation outside the > lock. > > Fixes: 2d1e952a2b8e ("mailbox: mailbox-test: Fix potential double-free in mbox_test_message_write()") > Signed-off-by: Dan Carpenter > --- > drivers/mailbox/mailbox-test.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) Reviewed-by: Lee Jones > diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c > index c4a705c30331..fc6a12a51b40 100644 > --- a/drivers/mailbox/mailbox-test.c > +++ b/drivers/mailbox/mailbox-test.c > @@ -98,6 +98,7 @@ static ssize_t mbox_test_message_write(struct file *filp, > size_t count, loff_t *ppos) > { > struct mbox_test_device *tdev = filp->private_data; > + char *message; > void *data; > int ret; > > @@ -113,12 +114,13 @@ static ssize_t mbox_test_message_write(struct file *filp, > return -EINVAL; > } > > - mutex_lock(&tdev->mutex); > - > - tdev->message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL); > - if (!tdev->message) > + message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL); > + if (!message) > return -ENOMEM; > > + mutex_lock(&tdev->mutex); > + > + tdev->message = message; > ret = copy_from_user(tdev->message, userbuf, count); > if (ret) { > ret = -EFAULT; > -- > 2.39.2 > -- Lee Jones [李琼斯]