From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7034B184533; Sun, 1 Sep 2024 16:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725207845; cv=none; b=g3d+iPWPi1zkQSczOT/BDKAkZ7zwQf0fJJtD6mP8KxvMLvS/LmPOt+Bui2NyzPdd1m5SuExa61d7G/3ZEnzKtKnk2NlVvCllqkzeqcThiGgBuJvtKgqzzNtfRc/U0hzptH9g5n2asS4Bw4AzQowSDuTxFN7lJ7Ct6AL7W++6FHY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725207845; c=relaxed/simple; bh=UcVd8XtjP+U2/D3/7Xvdb1Dpb8G5C9qvExsXfjWG25s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AxtRXoukbUMridKWU4AH26xweMgvy5almVBca+2IyOzTqUWX5k5pY0t83Agh6DHorLKpLcqtxpARbVR68V0dTQIrONjdOUrxRkzb+dvwmB8YR4HRNtWye6yzG+6VhaKUjI9QFW+tJFPkT6envWkEC8Ha+RbBXRvyfLJDv811WJU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VgJmxWAO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VgJmxWAO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9976FC4CEC4; Sun, 1 Sep 2024 16:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725207845; bh=UcVd8XtjP+U2/D3/7Xvdb1Dpb8G5C9qvExsXfjWG25s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VgJmxWAOsnuVMNw3m/gY6uCEHDpZtK2/PDwkPEa2zVl+L3pTKl0/eN6U7DzXbXPtG D3pim11i+sIlGjJNQnkX5bus6JdMeML6S+4ZOjyynhDIBGoFh261Iw4RaYmaUE2TX4 gEzXNt+VKDLtAsNMxuROb4BnZ81VQbwCm9pSaZW0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , Ulf Hansson , Sasha Levin Subject: [PATCH 4.19 63/98] mmc: mmc_test: Fix NULL dereference on allocation failure Date: Sun, 1 Sep 2024 18:16:33 +0200 Message-ID: <20240901160806.075952327@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240901160803.673617007@linuxfoundation.org> References: <20240901160803.673617007@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter [ Upstream commit a1e627af32ed60713941cbfc8075d44cad07f6dd ] If the "test->highmem = alloc_pages()" allocation fails then calling __free_pages(test->highmem) will result in a NULL dereference. Also change the error code to -ENOMEM instead of returning success. Fixes: 2661081f5ab9 ("mmc_test: highmem tests") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/8c90be28-67b4-4b0d-a105-034dc72a0b31@stanley.mountain Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/core/mmc_test.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c index ef18daeaa4cc6..164b4e43050e7 100644 --- a/drivers/mmc/core/mmc_test.c +++ b/drivers/mmc/core/mmc_test.c @@ -3101,13 +3101,13 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf, test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL); #ifdef CONFIG_HIGHMEM test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER); + if (!test->highmem) { + count = -ENOMEM; + goto free_test_buffer; + } #endif -#ifdef CONFIG_HIGHMEM - if (test->buffer && test->highmem) { -#else if (test->buffer) { -#endif mutex_lock(&mmc_test_lock); mmc_test_run(test, testcase); mutex_unlock(&mmc_test_lock); @@ -3115,6 +3115,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf, #ifdef CONFIG_HIGHMEM __free_pages(test->highmem, BUFFER_ORDER); +free_test_buffer: #endif kfree(test->buffer); kfree(test); -- 2.43.0