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 A9C2E28A411; Fri, 6 Jun 2025 15:44:14 +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=1749224654; cv=none; b=O8/Swk9uRo9mnqHl7KEFOVsGdNtt19LjOZ/er1Tv8Ep9g/Dh0V+VV+h61p20FFDErFUOWsV5Zxz0DsgGuPqSP1Pdt//MlNWMS/2EaENAWlEZ9516ywAVfisiGsuZ53XiY5WmW4irzV1DshEafTkvXA9WpBV5pu9tmS3oFoy8xBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224654; c=relaxed/simple; bh=4hZWSSBiBmXgCZRjHUQHX6vSbzo+EvjVtjI/uIdFtzg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WIz3uqRNTzih6D921OCtKnjX3bEg4Z2Jl0BtXnpxminBpNnF/4u1qrZsG1v2VOq85aJONBNM/KN0thhqtVMpp/qGMz6DDNqA33jil7oIFNumFk5BtRT2+R2KGb1kXKUz0/ny/UdG/zXLwPX3uixWd8CvbpzI6k6GUxIfQ0DE098= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZJiIRsPN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZJiIRsPN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAB77C4CEEB; Fri, 6 Jun 2025 15:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749224654; bh=4hZWSSBiBmXgCZRjHUQHX6vSbzo+EvjVtjI/uIdFtzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZJiIRsPN9lKEs+00mT7wk1mGLVbzqP2MGEKDxM/XsTiwEsZoKIGhwEnXfL9VgH08o llhboz7YTKVtq9muUS87RcaTlx9lU3L+n7AUzpWThyj5ahI3eBgGO6G10ehq/ANpfj 6Q21i6rbOmOOEu0MQ8S9vUQZu3PclHaBHOa9tcWD1cgQDhls4QZ/j7C2AnlM8j2O2g aN4E+vSz8++Q41vMvGpdHC+FWSL0XW2iFE03axjmyHnEVrC6wAmF26CfaZAgfXVEaR rct7bBrDk/dWcpXoDDMx9f/7ZjTc/L3MLJhmRHB3oixRpQOkqViIe5Vw5RHfHsoGAn dyzNlnUHe1zIg== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Peng Fan , Jassi Brar , Sasha Levin , linux-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 4/7] mailbox: Not protect module_put with spin_lock_irqsave Date: Fri, 6 Jun 2025 11:44:04 -0400 Message-Id: <20250606154408.548320-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250606154408.548320-1-sashal@kernel.org> References: <20250606154408.548320-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.185 Content-Transfer-Encoding: 8bit From: Peng Fan [ Upstream commit dddbd233e67e792bb0a3f9694a4707e6be29b2c6 ] &chan->lock is not supposed to protect 'chan->mbox'. And in __mbox_bind_client, try_module_get is also not protected by &chan->lock. So move module_put out of the lock protected region. Signed-off-by: Peng Fan Signed-off-by: Jassi Brar Signed-off-by: Sasha Levin --- **YES** This commit should be backported to stable kernel trees. **Analysis:** 1. **Clear Bug Fix**: The commit fixes an improper use of `module_put()` under a spinlock in `mbox_free_channel()`. Looking at the current code in `/home/sasha/linux/drivers/mailbox/mailbox.c:489`, `module_put()` is called while holding `&chan->lock` with `spin_lock_irqsave()`. 2. **Locking Inconsistency**: The commit message correctly identifies that `&chan->lock` is not supposed to protect `chan->mbox`. In `__mbox_bind_client()` (line 324), `try_module_get(chan->mbox->dev->driver->owner)` is called **outside** the spinlock protection, making the current `module_put()` placement inconsistent. 3. **Minimal Risk Change**: The fix is extremely simple and low-risk - it just moves one line (`module_put()`) outside the spinlock region. This maintains the same operation order but fixes the locking issue. 4. **No Side Effects**: Moving `module_put()` outside the lock doesn't change the functionality or introduce new race conditions. The `module_put()` implementation uses `atomic_dec_if_positive()`, so it's safe to call without additional locking. 5. **Follows Stable Rules**: This commit: - Fixes a real locking issue that could potentially cause problems - Is small and contained (single line move) - Has minimal regression risk - Doesn't introduce new features or architectural changes 6. **Similar Pattern**: Looking at similar commits in the historical references, commits that fix locking issues (like Similar Commit #5 which fixed a locking bug in mailbox-test) were marked as YES for backporting. The commit addresses a legitimate kernel locking violation where `module_put()` should not be called under a spinlock, making it a suitable candidate for stable tree backporting. drivers/mailbox/mailbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 6f54501dc7762..cb31ad917b352 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -459,8 +459,8 @@ void mbox_free_channel(struct mbox_chan *chan) if (chan->txdone_method == TXDONE_BY_ACK) chan->txdone_method = TXDONE_BY_POLL; - module_put(chan->mbox->dev->driver->owner); spin_unlock_irqrestore(&chan->lock, flags); + module_put(chan->mbox->dev->driver->owner); } EXPORT_SYMBOL_GPL(mbox_free_channel); -- 2.39.5