From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 C00B43A7F57 for ; Tue, 23 Jun 2026 05:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782192129; cv=none; b=AAWNeSvJ1Pxd0jdAvYBU6xP4JfkkK3/dAucrAU80cWhkqd8Fypu9d3caxw9pKXcSswryyFGa9b9ww/7kxxbTtC8NkyKRVobs625DbPm7gMIP/rlDFaH+r7cCpJBSc8A2otnZiQ+v3MszqVO4hK/iwXY0eQK8yR1cfdpPAsMeLmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782192129; c=relaxed/simple; bh=SDiiUWnqhJNEqF2a6+AgblFnyJmH35ewVs1RKIuJSzY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u/lBKsjSduum8PIlUTVa9Wb21C9zrJVqWKuCxFzhvQMHsiYbRcx/Im+gp9RCu6sCiGFCkY/CUUNcysYAh3wnZ+uk0l913Zzy93epTp4VPc9vKWheztk8j55Si+9CZisaHQAbs9nxj004hyrBYrMBNEFaBUqLW6CgZKNk84A10Wg= 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=KU4H060+; arc=none smtp.client-ip=74.125.82.176 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="KU4H060+" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-30c591fb1cbso483631eec.1 for ; Mon, 22 Jun 2026 22:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782192128; x=1782796928; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=upLE1c/n2AlRZEtEFhcrlAmqpNROOYKhcTi+a7geFuE=; b=KU4H060+3pri5Hy6f1aziOlHwVPPulOM1xKh/TB+yokhABTBsRDLiromRca1KImE4V vXcoZzyhUlV/q9VrYxoB0qaJoC6Abf+c2rvjqHVRqO98+GdMHfjfdCjIso9DRoF94baA qNfUBK9a/niHP4NSTCvyT4XIJtZwoFBT1PWTT9+lJK68yy8vKYDCZ32AkQ3P3fP/VzoX M3YpCM/JVbUtnvycWAKs6TT6O5w6FAxrsFuxTEhEHMaHlOOJCXXaZ57dNPHWLx7z9AmD KaM/gFVkr2DBDXPrSZ/Y66nr2mnWPPUYaSvVAgPbI60x3LhFxniBsQ/jZ3C3ua4q7gxE G/jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782192128; x=1782796928; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=upLE1c/n2AlRZEtEFhcrlAmqpNROOYKhcTi+a7geFuE=; b=rXOXnCfqkCof/HSCI512M64yQHIKl4+Dp9WQbnZrlgPFW6PPOku3LQtyG3xb8dQYZ/ X0SBE2aCiOtuefs63Y3mevgGLzIcz9vfZiopcwpKLPwU9EXEeUbZpOmVNGAX9r98Wfgd m8c+Cqxv1T6agAT/1X3b1h9DWBXYBTg61Lj0oxIwCnI0kV0Lg4lfSTQPYAAuU/ffqOTn y7RdYFXhUM9pEQ6f1HlGDy+q/BzFXYfonuZWeNXPTB8bQuhaPGlzegJ+RjE1JKE8+knv qVf6CmGqK/hpCkpy3kmDaRNZlkrm9ITk+usFNl77SyKoFj/0J0m3bENhc9MlHOythgAB gmqA== X-Forwarded-Encrypted: i=1; AHgh+RpjBwXGj4z66r4ss0/lDeJW2hoQUUVmZEBhasg4c578nc0hLT9PU6uMqTI+aNqLZaNDgPoJXD8Irztsecw=@vger.kernel.org X-Gm-Message-State: AOJu0YxMmuW4OLscFjEvG0H9EFnEPiQM5AeV0KY7Z4kT9H4IP0ezmZPo BqaY/+8kx4srJdWAnEvf0vDwiku9t74rllBUdZUCARDKbtvvqV0pYrGO X-Gm-Gg: AfdE7cnnhGNima/p/9zixOeETDuefxj2C8EG5mHnLSrt8YotNcRKvugOh2vSePXPZqb L1YecXQJzV5aGzOn0fR5S91XND8/j6Jwfy21eCbk3GtYcNqpVrFjuRtxObauFjl8a+gGts1hec7 SC2ZtBUUidO+PuW1VumKid+Ze7zt1tg2VCByZwzyOlMDSG9ojw4e98C9QRtPsIwE2Vrv7joqrQv eC0Hwvxms/I7XrzU1Ue8w5PhhoBWJ3gtMs9YPIekIYiARSC7GiwlXkHPTZov1pzeX0qsjsp30e0 jrVronIz1eEoeF2aOaPUC1NjcNClqQel4H5ZtG+1vVrXiBg1GyvgH7e2Tjf3Wu8dj3OqjFpm/J3 XndObWD5W7do1TIe7Zx8oFNqzkgOKij4XuSiUoChn7SB3gsSBaJGxibMzDcrsf4rxb6ORB94KFu oy8GV80e/okSemnfAtyr7mcJXYy9gkJWOv1aT+EKIYNdniwyWcsZbcHg== X-Received: by 2002:a05:7300:fb91:b0:30c:52c5:6e48 with SMTP id 5a478bee46e88-30c5b87aca1mr830395eec.18.1782192127715; Mon, 22 Jun 2026 22:22:07 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:7d8d:3bdf:d563:1911]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c1ba57db7sm12956602eec.7.2026.06.22.22.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 22:22:06 -0700 (PDT) Date: Mon, 22 Jun 2026 22:22:03 -0700 From: Dmitry Torokhov To: hexlabsecurity@proton.me Cc: Benjamin Tissoires , linux-input@vger.kernel.org, Andrew Duggan , linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: synaptics-rmi4 - bound the SMBus block read to the caller buffer Message-ID: References: <20260613-b4-disp-2e033955-v1-1-43ab7281667a@proton.me> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260613-b4-disp-2e033955-v1-1-43ab7281667a@proton.me> On Sat, Jun 13, 2026 at 12:39:32AM -0500, Bryam Vargas via B4 Relay wrote: > From: Bryam Vargas > > smb_block_read() takes a destination length but passes it nowhere: > > static int smb_block_read(struct rmi_transport_dev *xport, > u8 commandcode, void *buf, size_t len) > { > ... > retval = i2c_smbus_read_block_data(client, commandcode, buf); > > i2c_smbus_read_block_data() has no destination-size argument; it copies > the block count reported by the device (the first SMBus byte, up to > I2C_SMBUS_BLOCK_MAX = 32) into buf. The RMI callers pass buffers far > smaller than 32 bytes - rmi_read_pdt_entry() reads a PDT entry into an > on-stack u8 buf[RMI_PDT_ENTRY_SIZE] (6 bytes) during the PDT scan - so a > malfunctioning, malicious or counterfeit RMI4 SMBus controller (or an > attacker tampering with the I2C bus) that reports a larger block count > overflows the caller's stack buffer by up to 32 - 6 = 26 bytes, > clobbering the stack canary, saved registers and the return address. > > Read into a local I2C_SMBUS_BLOCK_MAX-sized buffer and copy back at most > len bytes, so the device can never write past the caller's buffer. > > Fixes: 82264d0cf7ae ("Input: synaptics-rmi4 - add SMBus support") > Cc: stable@vger.kernel.org > Signed-off-by: Bryam Vargas > --- > drivers/input/rmi4/rmi_smbus.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/input/rmi4/rmi_smbus.c b/drivers/input/rmi4/rmi_smbus.c > index f3d0b40721df..ea957aba28f1 100644 > --- a/drivers/input/rmi4/rmi_smbus.c > +++ b/drivers/input/rmi4/rmi_smbus.c > @@ -177,12 +177,20 @@ static int smb_block_read(struct rmi_transport_dev *xport, > struct rmi_smb_xport *rmi_smb = > container_of(xport, struct rmi_smb_xport, xport); > struct i2c_client *client = rmi_smb->client; > + u8 data[I2C_SMBUS_BLOCK_MAX]; > int retval; > > - retval = i2c_smbus_read_block_data(client, commandcode, buf); > + /* > + * i2c_smbus_read_block_data() copies the device-reported block count > + * (up to I2C_SMBUS_BLOCK_MAX) into the destination and has no way to > + * know its size, so read into a local buffer and copy back at most > + * len bytes - never past the caller's buffer. > + */ > + retval = i2c_smbus_read_block_data(client, commandcode, data); > if (retval < 0) > return retval; > > + memcpy(buf, data, min_t(size_t, retval, len)); Instead of doing extra copy I'd like to get the following in: https://lore.kernel.org/all/ZxGrwObOFkNuCn_w@google.com/ But unfortunately it has stalled. Can you try and see if it works for you? Thanks. -- Dmitry