Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp626436rwr; Fri, 5 May 2023 02:29:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7hcV1AW5iIPgV3NJqIB6uiMzk7dG6rC5UMQaT5qtb//GafwGh6kCJPdQPbskZfxJpTFuNB X-Received: by 2002:a05:6a00:2296:b0:63d:39a5:5bb9 with SMTP id f22-20020a056a00229600b0063d39a55bb9mr1199739pfe.7.1683278970228; Fri, 05 May 2023 02:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683278970; cv=none; d=google.com; s=arc-20160816; b=QtM0LHRPqXAzGZQgClyNaksxdkL9u6IBUZWwxTgQG4cJUecoMGnJ8SEZUlb+US5R2w 7JkOSRU7a0PxCWHGkT4B6qiKXXUvWYPFGUynphqONfXbKf7NhgPhqzMhEd2RFsEz2DAq th1B4PUff2ihnh4lrNsKL9qnDYUuWfwEc61lFivzhPIoFxRr/3hgbLpBNrrsg35fXjf+ R4QEDOp75CE/f67rCtEBdsMGNTVdKzCYJhf6PQpgPGy/5qoTCczGZMgetgcvZu+zSP9K 8BLwyWaJ5ru5lybO4lWQytdC+WRwZyreNh/XyHXc9Zdrwl9qRtivm0hjmFUwDAr643SR CroA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=7KhnBOIfg/E5fSoBayOzGobKvTaGcdmJ+k1kVchc46o=; b=MJrzuJplHhye9/BBmC3AAyA5UDJhBOSIcUtZEZQcJzzuXwh/Kdd+TOnEmA44/UEoea kxJ4Hv1NEddC5n2zOVjMooyaBfrbf4iMFRIeFSJFVVDea+nywWH3Rsq7bx515qhb9YTf noBKTSO1cROo9JmdDRSL4Rv5ZhxEdS2je6QgkxZnl4SsPK1+gwCmmcEwLVuz0gJ+YIrD cZ/TxYto9cgzOXt5E8woyt99F6geEGm3zTrbbOSnZyfLk6CGvNckb7sKw3BmfPvzo7r+ wt36HXd+7w3Lk0+qTnQsbElAetrqmi78YHzL9kQmRVRY70fBFrfNDXWx9ENdRMgSf0Bm dlAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XjuJnZSa; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q26-20020aa7961a000000b0063b731e3938si1673094pfg.2.2023.05.05.02.29.15; Fri, 05 May 2023 02:29:30 -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=@linaro.org header.s=google header.b=XjuJnZSa; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbjEEJWS (ORCPT + 99 others); Fri, 5 May 2023 05:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbjEEJWR (ORCPT ); Fri, 5 May 2023 05:22:17 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B09938A68 for ; Fri, 5 May 2023 02:22:15 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f1950f5676so15286145e9.3 for ; Fri, 05 May 2023 02:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683278534; x=1685870534; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=7KhnBOIfg/E5fSoBayOzGobKvTaGcdmJ+k1kVchc46o=; b=XjuJnZSaaR6TFbNwMQRlx8s2bUsaDFmD+36JmpeaJR5LRPb+FyyO/qbsTafZwQRhrR V6oLWPI9tFQf1BlLlUs+73l6jzK7UHW+3HRgFrCghOBeRAIYBrbBtsCcwLnuzYgmxtLg c869OSpF7XDDKMLW8zF1ZdfoW/GFObQtWn8MAipduXnP0YqKf1hTChA1FaLxFLMknDJh JRT7vD4zdjj3uO1ZzE6kNjQXsdAvU7519wFRVEAMl+S8iiAga39rAM4xWY3PNQ0yaZW3 TlTfWB4y53bm8B0uCY/1w64jYBJkBgtMCmqmWFv7/8T4qTQCRSHU2T8sZVMUq7/tzk+D vZlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683278534; x=1685870534; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7KhnBOIfg/E5fSoBayOzGobKvTaGcdmJ+k1kVchc46o=; b=Y8nsdPRQUVpRLlxTIeg66GIr0cIX4rEtMueidIcFLpitlfebTXHHQ0Afmh4Y3XmzhX /KSG1jkqLWE7JtVP9WvZ48a4QqZym3XyaGih3rhg4g2gyT00sk4U3mRbALOlR6nP+i2H Sycf3xvkqdCGjsFNh6q2i1KI5yxbec8Ch5BOWEm8HVzYt95nk488hGLu6wYdIdUROcod CS4++02yZ2yHTdQqpPi5xbsELyh52MdYuzXQZkZiAVj087QjhFpxJWPqSYQhxyAASn6s fHkXUEp6GCleSpPYnsMOr1wboLoRH2YueEujZBfwVi/uQ/YDLJILPl3+y4xvg8Y46Fs9 opIw== X-Gm-Message-State: AC+VfDwJb7r+u8FWOFRH/Uk0m0foD/VzPvpdSRfa1jm3d4h1nRnbV4wS 5zsAAwpixVBQoSLQGy8vS3M6QQ== X-Received: by 2002:a05:600c:218f:b0:3f0:a0bb:58ef with SMTP id e15-20020a05600c218f00b003f0a0bb58efmr695538wme.25.1683278534208; Fri, 05 May 2023 02:22:14 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id h15-20020a05600c314f00b003f1978bbcd6sm53668073wmo.3.2023.05.05.02.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 02:22:12 -0700 (PDT) Date: Fri, 5 May 2023 12:22:09 +0300 From: Dan Carpenter To: Lee Jones Cc: Jassi Brar , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] mailbox: mailbox-test: fix a locking issue in mbox_test_message_write() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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(-) 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