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 5288D18EB0 for ; Sun, 12 Apr 2026 12:55:20 +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=1775998520; cv=none; b=RvoT9jjba5KZu182BJFiyKLfhGnEih9HH1gCJN8j+g8yO0FHRe2uQ/fszXRJxEShjP7tJ192ZVS4tg+t1oYtGPUh/HglGOfQztFkbw+QtHpqoDmPpzghfyuYgKeOuVx13oIzLfvYtVpFuRSp0pY68B4yNKLHohbfu1MTzxl5D4c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775998520; c=relaxed/simple; bh=AwATX5nbBOftf0bMUoGhFfHeSPUGYHkchTfyuuL0GWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XoKDxJB8dFVGhy2pcyd5UivHXE41qkXsAXzT8Tgs+t4NuP7garM9UL+Uoa8k9KajyUT0IbcVk9x1P9JxE6rDkaadIS0Ga3e6coebvTlqsP2sQ+B9PrY0uySkb78cLNWioAyWjxd+GuPGu+NVqNvrj1BCPSfXFl0JgShF0R8UfCM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FSQeE3qA; 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="FSQeE3qA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C053C2BCB0; Sun, 12 Apr 2026 12:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775998520; bh=AwATX5nbBOftf0bMUoGhFfHeSPUGYHkchTfyuuL0GWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FSQeE3qAi7g021H5cNm9eJSfCWv26XmciE8naSrHVpDrlqWwq0oYZHC5Be8crM1uf Bd+2aIr0vIY8TWwGYRilOhFfw3sYymapU7K+Jd390Z9QM17A9EGSn1q/5EDSl2582Q rpAqXHFJ78W4lKJ8NcLOKnZS+mgI1V+K/u6UymGfQ7pvrsNxqcY8O6p6UC5bKpP6D+ 9VYbc7Ei7KkyHHfEkYk9t5DZKNKHVX4PqQ6+RDZrV+e+Nf4rmM1Z1gPCua+HfCtJoQ d5T//Vrl2zmGIcTBqbIxfBOF6VP16UFQUTZFwlb923k+mrh0p3icx6vD+hg476rtfb ax13N4oc80Q6A== From: Sasha Levin To: stable@vger.kernel.org Cc: Johannes Berg , Sasha Levin Subject: [PATCH 6.1.y 2/4] rfkill: sync before userspace visibility/changes Date: Sun, 12 Apr 2026 08:55:15 -0400 Message-ID: <20260412125517.2219007-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260412125517.2219007-1-sashal@kernel.org> References: <2026041215-clamp-serpent-1558@gregkh> <20260412125517.2219007-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg [ Upstream commit 2c3dfba4cf84ac4f306cc6653b37b6dd6859ae9d ] If userspace quickly opens /dev/rfkill after a new instance was created, it might see the old state of the instance from before the sync work runs and may even _change_ the state, only to have the sync work change it again. Fix this by doing the sync inline where needed, not just for /dev/rfkill but also for sysfs. Signed-off-by: Johannes Berg Stable-dep-of: ea245d78dec5 ("net: rfkill: prevent unlimited numbers of rfkill events from being created") Signed-off-by: Sasha Levin --- net/rfkill/core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 65913ac35bd59..981771598f1eb 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -48,6 +48,7 @@ struct rfkill { bool persistent; bool polling_paused; bool suspended; + bool need_sync; const struct rfkill_ops *ops; void *data; @@ -368,6 +369,17 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked) rfkill_event(rfkill); } +static void rfkill_sync(struct rfkill *rfkill) +{ + lockdep_assert_held(&rfkill_global_mutex); + + if (!rfkill->need_sync) + return; + + rfkill_set_block(rfkill, rfkill_global_states[rfkill->type].cur); + rfkill->need_sync = false; +} + static void rfkill_update_global_state(enum rfkill_type type, bool blocked) { int i; @@ -730,6 +742,10 @@ static ssize_t soft_show(struct device *dev, struct device_attribute *attr, { struct rfkill *rfkill = to_rfkill(dev); + mutex_lock(&rfkill_global_mutex); + rfkill_sync(rfkill); + mutex_unlock(&rfkill_global_mutex); + return sysfs_emit(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0); } @@ -751,6 +767,7 @@ static ssize_t soft_store(struct device *dev, struct device_attribute *attr, return -EINVAL; mutex_lock(&rfkill_global_mutex); + rfkill_sync(rfkill); rfkill_set_block(rfkill, state); mutex_unlock(&rfkill_global_mutex); @@ -783,6 +800,10 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, { struct rfkill *rfkill = to_rfkill(dev); + mutex_lock(&rfkill_global_mutex); + rfkill_sync(rfkill); + mutex_unlock(&rfkill_global_mutex); + return sysfs_emit(buf, "%d\n", user_state_from_blocked(rfkill->state)); } @@ -805,6 +826,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, return -EINVAL; mutex_lock(&rfkill_global_mutex); + rfkill_sync(rfkill); rfkill_set_block(rfkill, state == RFKILL_USER_STATE_SOFT_BLOCKED); mutex_unlock(&rfkill_global_mutex); @@ -1032,14 +1054,10 @@ static void rfkill_uevent_work(struct work_struct *work) static void rfkill_sync_work(struct work_struct *work) { - struct rfkill *rfkill; - bool cur; - - rfkill = container_of(work, struct rfkill, sync_work); + struct rfkill *rfkill = container_of(work, struct rfkill, sync_work); mutex_lock(&rfkill_global_mutex); - cur = rfkill_global_states[rfkill->type].cur; - rfkill_set_block(rfkill, cur); + rfkill_sync(rfkill); mutex_unlock(&rfkill_global_mutex); } @@ -1087,6 +1105,7 @@ int __must_check rfkill_register(struct rfkill *rfkill) round_jiffies_relative(POLL_INTERVAL)); if (!rfkill->persistent || rfkill_epo_lock_active) { + rfkill->need_sync = true; schedule_work(&rfkill->sync_work); } else { #ifdef CONFIG_RFKILL_INPUT @@ -1171,6 +1190,7 @@ static int rfkill_fop_open(struct inode *inode, struct file *file) ev = kzalloc(sizeof(*ev), GFP_KERNEL); if (!ev) goto free; + rfkill_sync(rfkill); rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); list_add_tail(&ev->list, &data->events); } -- 2.53.0