linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>, Daniel Scally <djrscally@gmail.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-acpi@vger.kernel.org, devel@acpica.org
Subject: [PATCH AUTOSEL 5.4 9/9] ACPI: fix NULL pointer dereference
Date: Tue, 27 Jul 2021 09:20:01 -0400	[thread overview]
Message-ID: <20210727132002.835130-9-sashal@kernel.org> (raw)
In-Reply-To: <20210727132002.835130-1-sashal@kernel.org>

From: Linus Torvalds <torvalds@linux-foundation.org>

[ Upstream commit fc68f42aa737dc15e7665a4101d4168aadb8e4c4 ]

Commit 71f642833284 ("ACPI: utils: Fix reference counting in
for_each_acpi_dev_match()") started doing "acpi_dev_put()" on a pointer
that was possibly NULL.  That fails miserably, because that helper
inline function is not set up to handle that case.

Just make acpi_dev_put() silently accept a NULL pointer, rather than
calling down to put_device() with an invalid offset off that NULL
pointer.

Link: https://lore.kernel.org/lkml/a607c149-6bf6-0fd0-0e31-100378504da2@kernel.dk/
Reported-and-tested-by: Jens Axboe <axboe@kernel.dk>
Tested-by: Daniel Scally <djrscally@gmail.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/acpi/acpi_bus.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 4d67a67964fa..1e5ae3b01eb2 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -681,7 +681,8 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
 
 static inline void acpi_dev_put(struct acpi_device *adev)
 {
-	put_device(&adev->dev);
+	if (adev)
+		put_device(&adev->dev);
 }
 #else	/* CONFIG_ACPI */
 
-- 
2.30.2


      parent reply	other threads:[~2021-07-27 13:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 13:19 [PATCH AUTOSEL 5.4 1/9] regulator: rt5033: Fix n_voltages settings for BUCK and LDO Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 2/9] spi: stm32h7: fix full duplex irq handler handling Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 3/9] ASoC: tlv320aic31xx: fix reversed bclk/wclk master bits Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 4/9] r8152: Fix potential PM refcount imbalance Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 5/9] qed: fix possible unpaired spin_{un}lock_bh in _qed_mcp_cmd_and_union() Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 6/9] mt7530 fix mt7530_fdb_write vid missing ivl bit Sasha Levin
2021-07-27 13:19 ` [PATCH AUTOSEL 5.4 7/9] net: Fix zero-copy head len calculation Sasha Levin
2021-07-27 13:20 ` [PATCH AUTOSEL 5.4 8/9] nvme: fix nvme_setup_command metadata trace event Sasha Levin
2021-07-27 13:20 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210727132002.835130-9-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=devel@acpica.org \
    --cc=djrscally@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).