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 EDF7812CDB1; Tue, 30 Apr 2024 10:54:22 +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=1714474463; cv=none; b=KZo+IyDvqZIWShj7kOuRvI4xUmkSLmDANef2mWya26aZnxChYSTQwct9DHoFQ/+Rg6Dujqs0yvnyW4YbJCeLX1Qz/m63hCihcrhBLWQC0/08WIHa/VgLL/kW1S1grsyCUskGdqiy22h65OcFEI+3RwQOLynMWdRylw3Jb10zBkk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714474463; c=relaxed/simple; bh=APU8sp3IpD5t97Uoo7KNQr7h+b2NhYbAvd0D8nN8wdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UYby6wJd5vhrBgbliiSoG0u1TivTgL1H666iqwIWpiONKTNv8lSiQuhinszMdVmoxl/8ZQ1VdlN5fwQUOUUCCG5HFJ7JVp96nMsrpvBM12x/a0+wKhPAHGswd2+Vs0XSA8EKhh6f9VqtYlaUW79tWrBcMzrHmmQqVRUH2y4/1Jo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uO2OnjJ4; 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="uO2OnjJ4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64BA1C2BBFC; Tue, 30 Apr 2024 10:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714474462; bh=APU8sp3IpD5t97Uoo7KNQr7h+b2NhYbAvd0D8nN8wdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uO2OnjJ4uTorcwQXBnG2oE5gKfaWkvrsBZJunzFCaU0gIB1joUkVF8SES/PLcR6P+ oqUO9Qxuv4bPIp0HOlK9vMf2BvAvs60VzAC7tn68l2EPF7LniAfNz+qFJl5g/D+Mux qUvYLUWdNHVD/DDqxXH93qqgUpJJ+bPiEBKub3l8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Daniel Okazaki , Bartosz Golaszewski Subject: [PATCH 6.8 164/228] eeprom: at24: fix memory corruption race condition Date: Tue, 30 Apr 2024 12:39:02 +0200 Message-ID: <20240430103108.539492167@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103103.806426847@linuxfoundation.org> References: <20240430103103.806426847@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 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Okazaki commit f42c97027fb75776e2e9358d16bf4a99aeb04cf2 upstream. If the eeprom is not accessible, an nvmem device will be registered, the read will fail, and the device will be torn down. If another driver accesses the nvmem device after the teardown, it will reference invalid memory. Move the failure point before registering the nvmem device. Signed-off-by: Daniel Okazaki Fixes: b20eb4c1f026 ("eeprom: at24: drop unnecessary label") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240422174337.2487142-1-dtokazaki@google.com Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/misc/eeprom/at24.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -758,15 +758,6 @@ static int at24_probe(struct i2c_client } pm_runtime_enable(dev); - at24->nvmem = devm_nvmem_register(dev, &nvmem_config); - if (IS_ERR(at24->nvmem)) { - pm_runtime_disable(dev); - if (!pm_runtime_status_suspended(dev)) - regulator_disable(at24->vcc_reg); - return dev_err_probe(dev, PTR_ERR(at24->nvmem), - "failed to register nvmem\n"); - } - /* * Perform a one-byte test read to verify that the chip is functional, * unless powering on the device is to be avoided during probe (i.e. @@ -782,6 +773,15 @@ static int at24_probe(struct i2c_client } } + at24->nvmem = devm_nvmem_register(dev, &nvmem_config); + if (IS_ERR(at24->nvmem)) { + pm_runtime_disable(dev); + if (!pm_runtime_status_suspended(dev)) + regulator_disable(at24->vcc_reg); + return dev_err_probe(dev, PTR_ERR(at24->nvmem), + "failed to register nvmem\n"); + } + /* If this a SPD EEPROM, probe for DDR3 thermal sensor */ if (cdata == &at24_data_spd) at24_probe_temp_sensor(client);