From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90A8C4F7993 for ; Mon, 28 Sep 2026 20:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790625817; cv=none; b=V62hTBpRqt+fw5Jjs9dfuXzFkD+o7OttDgcg0bbOaFwbht5ESGCxgBG2jZa7KpNn+KKdQORMlszrioYylcRaVzViSbdOHKmEsFiQsiWrfX4t9iwX2bguzDY9N+ctv4Hk5vpPii7uM1+o9dxcg89pppIAmJQ4sFG5er3KKEqqRVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790625817; c=relaxed/simple; bh=rCH+vNfr+HAz68hgE6ad8RdsLo1ZvJU0FFwXRjA0dbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=INbqjpyKzITt6rbV+k05xr2qVrgFWXrNO+WGNp8CMOY/n5BGwFujVgED12UZQGqOdO0a+SBvJHzT3BATNIyMvhz/VpkxJIQAU8PxCVlbqL4h2Hwzjzh7kEouHID9UPZ3/qCUbjlBkmvYhqkLjhpU/NYoSvNn0aSB8DJQ40Zbu3I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gSL1+QI8; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gSL1+QI8" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49fe8bf173aso18276835e9.3 for ; Mon, 28 Sep 2026 13:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790625813; x=1791230613; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=a2byg8jmBVjsxhPhVSYeY+o32k/rUgSaVIfDZBu776Q=; b=gSL1+QI8iOgw1fW2yvak7CYkKOALBOMFGGQfz5fKY7zMvgyE4IVbXYzMhpzgpKwhMk Mb/VMOn+71s1Jch8pvUSV9kgSK9P/W6sVd5N1yP4w/juTnJ1qKnaxlW02HnLbEENaa05 Y83XM+LP6cp9FWulKR8ATyQtJm0Nhj/gJ0zkPLNRXBfROeiZfuLxP5mtPHl7FMSAIyYC +VGxUFGoqxberTbxgY2N3NNf465XejcFslLEtxeCZu+ig6Z7tF4StmNx2h5yOA9eEme4 mmt/bGiwzd/qNrrkIXyGm/AXXjlEQ76eA5raJ38fBochTQaMo89ap11s6DbDrSBljG// fi/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790625813; x=1791230613; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=a2byg8jmBVjsxhPhVSYeY+o32k/rUgSaVIfDZBu776Q=; b=f2Jp5yUyvqwfs3T2O180WbcG6xt1sTky27A6aHSDk5IwiIM9wzlsey966ZdtCXVvM6 7HjjalrCk24iMD78M7xl9McZ5hh6Mg1wSOZjWVEDM93SudMEqjg5nqBiSJr2BtGh9e4l xhxVGS1Md/rFCmk0oubH/nIHfdcYHWqNRFx8y8ToewZvxiPsHo8NDzRWl4tUo966DXUP dGN8Pe6vaqTkBdGXkod1tv52DLSXkdROc44Q8TsfVP89t5iQ2n48lZWAhV5p38S6k6iK zhmF1BzLT/LmTVQj3DrBV3QnTUf2avlcHJsB5eK6iCppkSVYzX4TnmcJkEAacQz4RjsX 1UCg== X-Forwarded-Encrypted: i=1; AKwUvBw8BfwoiZHRQZYetDBCBBmhkc5J8qTINk8szNHaa70HAKw3JUSIm+kqSwoVPSJXkl3kEdHvei/b8sHRT/Y=@vger.kernel.org X-Gm-Message-State: AFuF++kvSHacZ6PWg7uP0JAoA4GI4tCZF3X74xYKyNcCAgUugDzUM9ml Y7C1cAI+YX1A6NJ6rOrT5B2Oke7ozUm1sZF4ZVI8oyqcjgrjYKlf9eKF X-Gm-Gg: AYBFou03q38MW2aTKHf0ST5x1/omc0soCQlM42pZYDzXGqbiT8KmwPHbBNK5VzwSWcH FckO3maYjRRbp4mZMsKaRN0aZ02ZrnT8J04IR2k8o3U1P6QlXry4OgmtqmSHFQJmkgEkQc6Dczn PuQrY8o68AqOc2zvY3sGGQn+OWWW7bjjMVf4muvyQBooUCWHZYBV5wuy6pz8WRnK+t94TXRhPz8 vk6A+XggU8BQ/bQCe/mtMF8ua+vKvSbuGD0otPkjGbhGjwm5PGvv0jkxAXvML44vWu/3frU/zZ6 wXcGTCVlO8pXGhXdKPJEZucMCycWRfdQeRA2PwSTDBik0yPg8eQnKNiZcCpAP9QzSAdU6APhfZw XVde7ok3mzRj+MXhOD79OOW9CIax0hwH+tDVaej/fZnVxwkZdyBYJYMijABHoM9aU6BSybgjAiY EJ1seyi1PRj1pVOuR+M30foosLuCyt6u+FhC/66Q17ts9Mt9kI67gjTA4pUEr6UjNFyhHXWL/I2 53rNARVm9n60rjPh8lzp2RbFowwolbpoD4weQvqubdxIrsXeSOs X-Received: by 2002:a05:600c:530f:b0:49f:ffdc:939d with SMTP id 5b1f17b1804b1-49fffdc9a4amr81501985e9.9.1790625812777; Mon, 28 Sep 2026 13:03:32 -0700 (PDT) Received: from fedora ([202.47.63.86]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a00c0730a8sm26506625e9.0.2026.09.28.13.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2026 13:03:31 -0700 (PDT) From: Muhammad Bilal To: Jorge Lopez , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Muhammad Bilal Subject: [PATCH v2 1/3] platform/x86: hp-bioscfg: fix OOB reads in hp_get_string_from_buffer() Date: Tue, 29 Sep 2026 01:03:16 +0500 Message-ID: <20260928200318.63383-2-meatuni001@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260928200318.63383-1-meatuni001@gmail.com> References: <20260928200318.63383-1-meatuni001@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The escape-prescan loop uses 'size' as both loop bound and accumulator, so each match extends the bound and reads past src[]: for (i = 0; i < size; i++) if (src[i] == '\\' || ...) size++; Snapshot the real char count into orig_size and loop against that. Also fix two adjacent issues: the bounds check omits the 2-byte length prefix already consumed, and utf16s_to_utf8s() receives the byte count (src_size) instead of the u16-unit count (orig_size). Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7). Suggested-by: Ilpo Järvinen Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg") Cc: stable@vger.kernel.org Signed-off-by: Muhammad Bilal --- Changes in v2: - Split bounds and prescan OOB fix into a separate patch, as reviewed by Ilpo Järvinen. drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c index 32b99a862082..ab1eff1deca1 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c @@ -60,6 +60,7 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ u16 *src = (u16 *)*buffer; u16 src_size; + u16 orig_size; u16 size; int i; int conv_dst_size; @@ -67,17 +68,20 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ if (*buffer_size < sizeof(u16)) return -EINVAL; - src_size = *(src++); - /* size value in u16 chars */ - size = src_size / sizeof(u16); + src_size = *src; - /* Ensure there is enough space remaining to read and convert - * the string + /* Ensure there is enough space remaining for the length prefix + * just read plus the string data it describes. */ - if (*buffer_size < src_size) + if (*buffer_size < sizeof(u16) + src_size) return -EINVAL; - for (i = 0; i < size; i++) + src++; + /* size value in u16 chars */ + orig_size = src_size / sizeof(u16); + size = orig_size; + + for (i = 0; i < orig_size; i++) if (src[i] == '\\' || src[i] == '\r' || src[i] == '\n' || @@ -95,7 +99,7 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ /* * convert from UTF-16 unicode to ASCII */ - utf16s_to_utf8s(src, src_size, UTF16_HOST_ENDIAN, dst, conv_dst_size); + utf16s_to_utf8s(src, orig_size, UTF16_HOST_ENDIAN, dst, conv_dst_size); dst[conv_dst_size] = 0; for (i = 0; i < conv_dst_size; i++) { @@ -121,8 +125,8 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ src++; } - *buffer = (u8 *)src; - *buffer_size -= size * sizeof(u16); + *buffer += sizeof(u16) + src_size; + *buffer_size -= sizeof(u16) + src_size; return size; } -- 2.55.0