diff options
| author | Muhammad Bilal <meatuni001@gmail.com> | 2026-07-28 17:54:55 +0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-09-01 12:15:16 +0200 |
| commit | ff917923f4fb9c83717ba135ee47d7e4c1567bb7 (patch) | |
| tree | c38fd8fcf58e1937b17fdbc6518b6f8b797fc15a /tools/platform | |
| download | linux-stable-ff917923f4fb9c83717ba135ee47d7e4c1567bb7.tar.gz linux-stable-ff917923f4fb9c83717ba135ee47d7e4c1567bb7.zip | |
staging: rtl8723bs: fix OOB read in rtw_action_frame_parse()grafted
rtw_action_frame_parse() takes a frame_len parameter but never
actually checks it before indexing into the frame body:
const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr);
...
c = frame_body[0];
...
a = frame_body[1];
frame_body already points 24 bytes (sizeof(struct
ieee80211_hdr_3addr)) into frame, so reading frame_body[0] and
frame_body[1] requires frame_len >= 26. A management action frame
shorter than that (e.g. exactly 24 bytes, the minimum a malicious
peer can send) causes a 1-2 byte out-of-bounds read.
This is reachable from rtw_cfg80211_monitor_if_xmit_entry() and
cfg80211_rtw_mgmt_tx() in ioctl_cfg80211.c, both of which pass
attacker/user-influenced frame buffers and lengths straight through.
Add the missing length check before frame_body is dereferenced.
Fixes: 554c0a3abf216 ("staging: Add rtl8723bs sdio wifi driver")
Cc: stable@vger.kernel.org
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
Link: https://patch.msgid.link/20260728125456.32359-3-meatuni001@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/platform')
| -rw-r--r-- | tools/platform/x86/amd/Makefile | 60 | ||||
| -rw-r--r-- | tools/platform/x86/amd/test-pmf.c | 142 |
2 files changed, 202 insertions, 0 deletions
diff --git a/tools/platform/x86/amd/Makefile b/tools/platform/x86/amd/Makefile new file mode 100644 index 000000000..5d820df58 --- /dev/null +++ b/tools/platform/x86/amd/Makefile @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: GPL-2.0 +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +endif + +# Include common tools build infrastructure +include $(srctree)/tools/scripts/Makefile.include + +CC = $(CROSS_COMPILE)gcc +BUILD_OUTPUT := $(CURDIR) +PREFIX ?= /usr +DESTDIR ?= + +ifeq ("$(origin O)", "command line") + BUILD_OUTPUT := $(O) +endif + +# Include paths: tools/include has linux/kernel.h with ARRAY_SIZE +INCLUDES = -I$(srctree)/tools/include +INCLUDES += -I$(srctree)/tools/include/uapi +INCLUDES += -I$(srctree)/include/uapi +INCLUDES += -I$(srctree)/include + +override CFLAGS += -O2 -Wall -Wextra -D_GNU_SOURCE $(INCLUDES) +override CFLAGS += -D_FILE_OFFSET_BITS=64 +override CFLAGS += -D__EXPORTED_HEADERS__ + +TARGETS = test_amd_pmf + +all: $(TARGETS) + +test_amd_pmf: test-pmf.c + $(QUIET_CC)$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) + +.PHONY: clean +clean: + $(call QUIET_CLEAN, test_amd_pmf)$(RM) $(BUILD_OUTPUT)/test_amd_pmf + +.PHONY: install +install: $(TARGETS) + $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin + $(INSTALL) $(BUILD_OUTPUT)/test_amd_pmf $(DESTDIR)$(PREFIX)/bin/test_amd_pmf + +.PHONY: help +help: + @echo "AMD Platform Tools Makefile" + @echo "" + @echo "Targets:" + @echo " all - Build all tools (default)" + @echo " test_amd_pmf - Build the PMF test tool" + @echo " clean - Remove built files" + @echo " install - Install tools to $(PREFIX)/bin" + @echo "" + @echo "Variables:" + @echo " O=<dir> - Build output directory" + @echo " PREFIX - Installation prefix (default: /usr)" + @echo " DESTDIR - Destination directory for install" diff --git a/tools/platform/x86/amd/test-pmf.c b/tools/platform/x86/amd/test-pmf.c new file mode 100644 index 000000000..82978afa6 --- /dev/null +++ b/tools/platform/x86/amd/test-pmf.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * AMD Platform Management Framework Test Tool + * + * Copyright (c) 2026, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> + * Sanket Goswami <Sanket.Goswami@amd.com> + */ + +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <sys/ioctl.h> +#include <unistd.h> + +#include <linux/amd-pmf.h> +#include <linux/kernel.h> + +#define DEVICE_NODE "/dev/amdpmf_interface" + +/* Feature flag names */ +static const char * const feature_names[] = { + "Auto Mode", + "Static Power Slider", + "Policy Builder (Smart PC)", + "Dynamic Power Slider AC", + "Dynamic Power Slider DC", +}; + +static const char *banner = + "====================================================\n" + " AMD PMF Metrics info and Feature Status\n" + "====================================================\n\n"; + +/* Print feature flags */ +static void pmf_print_features(uint32_t flags) +{ + size_t i; + + for (i = 0; i < ARRAY_SIZE(feature_names); i++) + printf(" [%c] %s\n", (flags & (1U << i)) ? 'x' : ' ', feature_names[i]); +} + +/* Print BIOS parameters */ +static void pmf_print_bios_params(const char *type, const __u32 *params) +{ + int i; + + for (i = 0; i < AMD_PMF_BIOS_PARAMS_MAX; i++) + printf(" Custom BIOS %s%d: %u\n", type, i + 1, params[i]); +} + +/* Open the PMF device */ +static int pmf_open_device(void) +{ + int fd; + + fd = open(DEVICE_NODE, O_RDONLY); + if (fd < 0) + fprintf(stderr, "Error: Cannot open %s: %s\n", DEVICE_NODE, strerror(errno)); + + return fd; +} + +/* Query PMF info using the single IOCTL */ +static int pmf_get_info(int fd, struct amd_pmf_info *info) +{ + int ret; + + /* Zero-initialize and set size for versioning */ + memset(info, 0, sizeof(*info)); + info->size = sizeof(*info); + + ret = ioctl(fd, IOCTL_AMD_PMF_POPULATE_DATA, info); + if (ret < 0) { + fprintf(stderr, "Error: IOCTL_AMD_PMF_POPULATE_DATA failed: %s\n", strerror(errno)); + return ret; + } + + return 0; +} + +static void pmf_print_info(const struct amd_pmf_info *info) +{ + printf("%s", banner); + + /* Feature status */ + printf("Feature Status:\n"); + pmf_print_features(info->features_supported); + + /* Device states */ + printf("\nDevice States:\n"); + printf(" Platform Type: %s\n", amd_pmf_get_platform_type(info->platform_type)); + printf(" Laptop Placement: %s\n", amd_pmf_get_laptop_placement(info->laptop_placement)); + printf(" Lid State: %s\n", info->lid_state ? "Closed" : "Open"); + printf(" User Presence: %s\n", info->user_presence ? "Present" : "Away"); + printf(" Slider Position: %s\n", amd_pmf_get_slider_position(info->slider_position)); + + /* Thermal and power metrics */ + printf("\nThermal/Power Metrics:\n"); + printf(" Skin Temperature: %d\n", info->skin_temp / 100); + printf(" GFX Busy: %u\n", info->gfx_busy); + printf(" Ambient Light: %d\n", info->ambient_light); + printf(" Avg C0 Residency: %u\n", info->avg_c0_residency); + printf(" Max C0 Residency: %u\n", info->max_c0_residency); + printf(" Socket Power: %u\n", info->socket_power); + + /* BIOS parameters */ + printf("\nCustom BIOS Input Parameters:\n"); + pmf_print_bios_params("Input", info->bios_input); + printf("\nCustom BIOS Output Parameters:\n"); + pmf_print_bios_params("Output", info->bios_output); + + printf("\n=================================================\n"); +} + +int main(void) +{ + struct amd_pmf_info info; + int fd, ret; + + fd = pmf_open_device(); + if (fd < 0) + return -1; + + /* Query all info with single IOCTL */ + ret = pmf_get_info(fd, &info); + close(fd); + + if (ret < 0) + return -1; + + pmf_print_info(&info); + + return 0; +} |
