From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 57E4E396565 for ; Fri, 26 Jun 2026 05:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782451091; cv=none; b=YXsmda1FengpLN9kAVXFysO/ml001sdNa2ibzAySGuUIW6RfYhYnpiLnLg9zGGJCpTWrz4Tbz1ZnwtlPMgykigSaGEMFdkN8zs7Dk0r8uUyOVLN94HDR4am4IHVUbPUFn55s2zHu+QWjYg10rYWkMTXjX7LDR6uOXC0HMxqCnoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782451091; c=relaxed/simple; bh=xzeEhHEyQCRH9yR9joDMads1uaHmYunLiX/nHJEP0QI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nVP8wjyZhNpNFKh3QwwFrfVvXHif+iRPgCk6rx7cN1HXN72kI8r4YJThoyHTenDWK5y8cwrwQ/EsvKm6dIeM1FtAiGRBgp+tUJxBANKnmGEX4jBHK8/HZL0HHpxixN84t/MWM+AtNwG27bzWDS6UvebdjhPOoc9Es7KP4UatsNM= 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=AFQHoXli; arc=none smtp.client-ip=74.125.82.177 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="AFQHoXli" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-304f590dd91so799243eec.0 for ; Thu, 25 Jun 2026 22:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782451089; x=1783055889; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xfyMoOrj1XhKeMiEVwgSjYoIFZP5QHNbRipRhkiiuRo=; b=AFQHoXli454V7cZcl+BG6hB+QvAWSTuMjcAEgTu+sjHXG+YKGVjC7s5ixKGwN3O2FZ /buHdbFyq/9aPzJjfGUgLzYghaIY0mU6766TgUSkUZWRLh8CJGYmj2so50ieAlg3t0hr 0apV+X80Gyu7hOgU7NFSpmlZe18UDZwVBi8sumLFdCcaGAcTRdZUHVkvQbJnhyuJ80EQ g9CmG5ohCw2G0w7se8J72fuiRdlXbqaJb/BZ3PFGt402mwRXSdyMItKwyb1MN3zp5KlG +IeC8BP2MIvvQBM/e+5CZhNOejeNpqzt7EB287Ht0bTN9ZfFIrsMhWxtnh37W1/3zEHK X2wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782451089; x=1783055889; h=content-transfer-encoding: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; bh=xfyMoOrj1XhKeMiEVwgSjYoIFZP5QHNbRipRhkiiuRo=; b=Ro1COsWwa1VhZrSdeq2VHuUfbfZ07EHaA67DGC3ftJYclo7J6PATolLNPcGgkxTMxA xAA/jywzFz2yrvn+b2LU1MAIkKXMSJKizNqT9QtD2tvk3maR1JZFb1AGWlioo51uGuPp ls9f3CC4a6O/3jhpNVCygAI5U7iotEAyyDEC/1PUVSmEBRwKwwQRWG95JLTPh3Sq6Qxd gqbNdb7/qyLXI73pztzS5WdJH635sHGwpyovJd4njPijcxVQDJhqsL7EDHeM0T3/mpm+ wVMtVq5w/eZIcjN0Pj3UENw55oxvUomxucQhBOymzUBil+2YnZ8UMbvaIvFW0ebXk2Ou guag== X-Forwarded-Encrypted: i=1; AHgh+Rqgbr0tzbsu2jodeS5dHZSln3li9LureX1MoYizq82SGKCAQWwCDIp9gvKw5xG6C9Zbh/9UzluOSUKKKv8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz14siolOyt7y/BfaBzQ6Aph45oG3UlbZjZVWzkZxpJW41WNRno Ht3YY/zr/cvZKvu+XJ6cugM0I0QODgIkIgxBmo8UcO94I++SP5q4N9g8 X-Gm-Gg: AfdE7cmyfwdWbQMzJmOenQH702eb2nUMTbyfIDoFzqFzk34i9J4hyIESG3BivT36YAK 1B0Or4tI3rZRqQgLI4NRbURab8LErxARHFBw52gkZrSBfrNADwIF+oss43/8lfr+US4JuMb2bHY /foZ+VfD+xkl5VWENzdPsycuylccqugCvtFa4PxPUYCrGDTN2Jo3BEumC3mRRfGhoqXXIC2UKmK 4qIqzMCg/tgUMzfFCwR4/2yg6QLwwY+E5hr8ySX/KWrCSFMxo1aaGbnDisLc9FJZv5cVsEepUNI IHvhcKTa/HDfsOQBAZQh5RGQixq/O8Bj7KKyOasUJtg7UHx4NWgy1MpzDtmrzVbwPTqte6dPOme iNahsnS++PhfwOfD9lSsGnKN/b4Jp4aXh/gOSF9b96Yb5Ssf6x5F0ud2roeFGGnJm2YbVufwsQq oGl2DMrh8BV/e3bfwcd8K5vqCqJjP5FuWQLfSFJHOC1E8soKe7umuvhupihsqLe966+vR6pFCX6 +U4ULuanb6QbYs= X-Received: by 2002:a05:7300:7246:b0:30c:5a5:df4f with SMTP id 5a478bee46e88-30c84eb9cf8mr6385940eec.16.1782451089397; Thu, 25 Jun 2026 22:18:09 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:a474:bf4a:4966:8d97]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c9e9214sm14804188eec.20.2026.06.25.22.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 22:18:08 -0700 (PDT) From: Dmitry Torokhov To: Bryam Vargas , Hans Verkuil Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 03/10] Input: synaptics-rmi4 - bound the F54 report size to the allocated buffer Date: Thu, 25 Jun 2026 22:17:52 -0700 Message-ID: <20260626051802.4033172-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog In-Reply-To: <20260626051802.4033172-1-dmitry.torokhov@gmail.com> References: <20260626051802.4033172-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Bryam Vargas rmi_f54_work() reads a diagnostics report from the device into f54->report_data, sizing the transfer with rmi_f54_get_report_size(): report_size = rmi_f54_get_report_size(f54); ... for (i = 0; i < report_size; i += F54_REPORT_DATA_SIZE) { int size = min(F54_REPORT_DATA_SIZE, report_size - i); ... rmi_read_block(.., f54->report_data + i, size); } report_data is allocated once at probe from F54's own electrode counts (array3_size(f54->num_tx_electrodes, f54->num_rx_electrodes, sizeof(u16))), but rmi_f54_get_report_size() computes the size from drv_data->num_*_electrodes when those are set, i.e. from the F55 function's electrode counts. Both counts come straight from device queries (F54 and F55 each report up to 255 electrodes) and nothing constrains the F55 counts to the F54 ones. A malicious or malfunctioning RMI4 device that reports larger F55 electrode counts than its F54 counts makes report_size exceed the allocation, so the read loop writes past report_data (and the V4L2 dequeue memcpy() then reads past it). On conforming hardware the F55 configured electrodes are a subset of the F54 physical electrodes, so report_size never exceeds the buffer and well-behaved devices are unaffected. Record the allocation size and reject a report that does not fit, mirroring the existing zero-size check. Fixes: c762cc68b6a1 ("Input: synaptics-rmi4 - propagate correct number of rx and tx electrodes to F54") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas Assisted-by: Antigravity:gemini-3.5-flash Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f54.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/input/rmi4/rmi_f54.c b/drivers/input/rmi4/rmi_f54.c index 8eac320c43e3..75839a54656b 100644 --- a/drivers/input/rmi4/rmi_f54.c +++ b/drivers/input/rmi4/rmi_f54.c @@ -104,6 +104,7 @@ struct f54_data { enum rmi_f54_report_type report_type; u8 *report_data; + size_t max_report_size; int report_size; bool is_busy; @@ -548,6 +549,13 @@ static void rmi_f54_work(struct work_struct *work) goto out; /* retry won't help */ } + if (report_size > f54->max_report_size) { + dev_err(&fn->dev, "Report size %d exceeds buffer size %zu\n", + report_size, f54->max_report_size); + error = -EINVAL; + goto out; + } + /* * Need to check if command has completed. * If not try again later. @@ -678,8 +686,8 @@ static int rmi_f54_probe(struct rmi_function *fn) rx = f54->num_rx_electrodes; tx = f54->num_tx_electrodes; - f54->report_data = devm_kzalloc(&fn->dev, - array3_size(tx, rx, sizeof(u16)), + f54->max_report_size = array3_size(tx, rx, sizeof(u16)); + f54->report_data = devm_kzalloc(&fn->dev, f54->max_report_size, GFP_KERNEL); if (f54->report_data == NULL) return -ENOMEM; -- 2.55.0.rc0.799.gd6f94ed593-goog