From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Martin Weinelt <martin@linuxlounge.net>,
Sven Eckelmann <sven@narfation.org>,
Antonio Quartulli <a@unstable.cc>,
Simon Wunderlich <sw@simonwunderlich.de>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.14 31/75] batman-adv: Reduce tt_global hash refcnt only for removed entry
Date: Mon, 6 May 2019 16:32:39 +0200 [thread overview]
Message-ID: <20190506143056.011292754@linuxfoundation.org> (raw)
In-Reply-To: <20190506143053.287515952@linuxfoundation.org>
[ Upstream commit f131a56880d10932931e74773fb8702894a94a75 ]
The batadv_hash_remove is a function which searches the hashtable for an
entry using a needle, a hashtable bucket selection function and a compare
function. It will lock the bucket list and delete an entry when the compare
function matches it with the needle. It returns the pointer to the
hlist_node which matches or NULL when no entry matches the needle.
The batadv_tt_global_free is not itself protected in anyway to avoid that
any other function is modifying the hashtable between the search for the
entry and the call to batadv_hash_remove. It can therefore happen that the
entry either doesn't exist anymore or an entry was deleted which is not the
same object as the needle. In such an situation, the reference counter (for
the reference stored in the hashtable) must not be reduced for the needle.
Instead the reference counter of the actually removed entry has to be
reduced.
Otherwise the reference counter will underflow and the object might be
freed before all its references were dropped. The kref helpers reported
this problem as:
refcount_t: underflow; use-after-free.
Fixes: 7683fdc1e886 ("batman-adv: protect the local and the global trans-tables with rcu")
Reported-by: Martin Weinelt <martin@linuxlounge.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Acked-by: Antonio Quartulli <a@unstable.cc>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/batman-adv/translation-table.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 6c3e446abeed..020a8adc4cce 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -614,14 +614,26 @@ static void batadv_tt_global_free(struct batadv_priv *bat_priv,
struct batadv_tt_global_entry *tt_global,
const char *message)
{
+ struct batadv_tt_global_entry *tt_removed_entry;
+ struct hlist_node *tt_removed_node;
+
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Deleting global tt entry %pM (vid: %d): %s\n",
tt_global->common.addr,
batadv_print_vid(tt_global->common.vid), message);
- batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt,
- batadv_choose_tt, &tt_global->common);
- batadv_tt_global_entry_put(tt_global);
+ tt_removed_node = batadv_hash_remove(bat_priv->tt.global_hash,
+ batadv_compare_tt,
+ batadv_choose_tt,
+ &tt_global->common);
+ if (!tt_removed_node)
+ return;
+
+ /* drop reference of remove hash entry */
+ tt_removed_entry = hlist_entry(tt_removed_node,
+ struct batadv_tt_global_entry,
+ common.hash_entry);
+ batadv_tt_global_entry_put(tt_removed_entry);
}
/**
--
2.20.1
next prev parent reply other threads:[~2019-05-06 14:44 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-06 14:32 [PATCH 4.14 00/75] 4.14.117-stable review Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 01/75] ALSA: line6: use dynamic buffers Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 02/75] ipv4: ip_do_fragment: Preserve skb_iif during fragmentation Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 03/75] ipv6/flowlabel: wait rcu grace period before put_pid() Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 04/75] ipv6: invert flowlabel sharing check in process and user mode Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 05/75] sctp: avoid running the sctp state machine recursively Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 06/75] packet: validate msg_namelen in send directly Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 07/75] bnxt_en: Improve multicast address setup logic Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 08/75] bnxt_en: Free short FW command HWRM memory in error path in bnxt_init_one() Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 09/75] rxrpc: Fix net namespace cleanup Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 10/75] net: phy: marvell: Fix buffer overrun with stats counters Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 11/75] net: dsa: bcm_sf2: fix buffer overflow doing set_rxnfc Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 12/75] kasan: remove redundant initialization of variable real_size Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 13/75] kasan: prevent compiler from optimizing away memset in tests Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 14/75] arm64: Fix single stepping in kernel traps Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 15/75] arm64: only advance singlestep for user instruction traps Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 16/75] caif: reduce stack size with KASAN Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 17/75] ALSA: hda/realtek - Add new Dell platform for headset mode Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 18/75] ALSA: hda/realtek - Fixed Dell AIO speaker noise Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 19/75] USB: yurex: Fix protection fault after device removal Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 20/75] USB: w1 ds2490: Fix bug caused by improper use of altsetting array Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 21/75] usb: usbip: fix isoc packet num validation in get_pipe Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 22/75] USB: core: Fix unterminated string returned by usb_string() Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 23/75] USB: core: Fix bug caused by duplicate interface PM usage counter Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 24/75] mm: do not stall register_shrinker() Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 25/75] nvme-loop: init nvmet_ctrl fatal_err_work when allocate Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 26/75] HID: logitech: check the return value of create_singlethread_workqueue Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 27/75] HID: debug: fix race condition with between rdesc_show() and device removal Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 28/75] rtc: sh: Fix invalid alarm warning for non-enabled alarm Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 29/75] batman-adv: Reduce claim hash refcnt only for removed entry Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 30/75] batman-adv: Reduce tt_local " Greg Kroah-Hartman
2019-05-06 14:32 ` Greg Kroah-Hartman [this message]
2019-05-06 14:32 ` [PATCH 4.14 32/75] ARM: dts: rockchip: Fix gpu opp node names for rk3288 Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 33/75] igb: Fix WARN_ONCE on runtime suspend Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 34/75] net/mlx5: E-Switch, Fix esw manager vport indication for more vport commands Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 35/75] bonding: show full hw address in sysfs for slave entries Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 36/75] net: stmmac: ratelimit RX error logs Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 37/75] net: stmmac: dont overwrite discard_frame status Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 38/75] net: stmmac: fix dropping of multi-descriptor RX frames Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 39/75] net: stmmac: dont log oversized frames Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 40/75] jffs2: fix use-after-free on symlink traversal Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 41/75] debugfs: " Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 42/75] rtc: da9063: set uie_unsupported when relevant Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 43/75] HID: input: add mapping for Assistant key Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 44/75] vfio/pci: use correct format characters Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 45/75] scsi: core: add new RDAC LENOVO/DE_Series device Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 46/75] scsi: storvsc: Fix calculation of sub-channel count Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 47/75] net: hns: fix KASAN: use-after-free in hns_nic_net_xmit_hw() Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 48/75] net: hns: Use NAPI_POLL_WEIGHT for hns driver Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 49/75] net: hns: Fix probabilistic memory overwrite when HNS driver initialized Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 50/75] net: hns: fix ICMP6 neighbor solicitation messages discard problem Greg Kroah-Hartman
2019-05-06 14:32 ` [PATCH 4.14 51/75] net: hns: Fix WARNING when remove HNS driver with SMMU enabled Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 52/75] kmemleak: powerpc: skip scanning holes in the .bss section Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 53/75] hugetlbfs: fix memory leak for resv_map Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 54/75] sh: fix multiple function definition build errors Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 55/75] xsysace: Fix error handling in ace_setup Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 56/75] ARM: orion: dont use using 64-bit DMA masks Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 57/75] ARM: iop: " Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 58/75] perf/x86/amd: Update generic hardware cache events for Family 17h Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 59/75] Bluetooth: btusb: request wake pin with NOAUTOEN Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 60/75] staging: iio: adt7316: allow adt751x to use internal vref for all dacs Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 61/75] staging: iio: adt7316: fix the dac read calculation Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 62/75] staging: iio: adt7316: fix the dac write calculation Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 63/75] scsi: RDMA/srpt: Fix a credit leak for aborted commands Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 64/75] ASoC: stm32: fix sai driver name initialisation Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 65/75] IB/core: Unregister notifier before freeing MAD security Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 66/75] IB/core: Fix potential memory leak while creating MAD agents Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 67/75] IB/core: Destroy QP if XRC QP fails Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 68/75] Input: snvs_pwrkey - initialize necessary driver data before enabling IRQ Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 69/75] Input: stmfts - acknowledge that setting brightness is a blocking call Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 70/75] selinux: never allow relabeling on context mounts Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 71/75] powerpc/mm/hash: Handle mmap_min_addr correctly in get_unmapped_area topdown search Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 72/75] x86/mce: Improve error message when kernel cannot recover, p2 Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 73/75] clk: x86: Add system specific quirk to mark clocks as critical Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 74/75] i2c: i2c-stm32f7: Fix SDADEL minimum formula Greg Kroah-Hartman
2019-05-06 14:33 ` [PATCH 4.14 75/75] media: v4l2: i2c: ov7670: Fix PLL bypass register values Greg Kroah-Hartman
2019-05-07 7:19 ` [PATCH 4.14 00/75] 4.14.117-stable review Naresh Kamboju
2019-05-07 12:44 ` Jon Hunter
2019-05-07 18:38 ` Guenter Roeck
2019-05-07 20:26 ` shuah
2019-05-07 22:47 ` kernelci.org bot
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=20190506143056.011292754@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=a@unstable.cc \
--cc=linux-kernel@vger.kernel.org \
--cc=martin@linuxlounge.net \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=sven@narfation.org \
--cc=sw@simonwunderlich.de \
/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).