From nobody Mon Jun 8 05:25:24 2026 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 EFFC021ADB7 for ; Sat, 6 Jun 2026 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780765420; cv=none; b=GlPwFONXy8LoWL0/VRvPKnxK5XcKV8SMi1zVKGvSmsDrCGZ8VJ13HCFIUH70i2KvvjkNBn9fzxp/7KRmQD70j4jFP3RyOIwSesiJDB0mm9Jw2HV7Jm6/ukkT8O4feEAMXk10U+IEkw+kAm+ZuDqm31LaOnuh7rwcr/7p9EeAOog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780765420; c=relaxed/simple; bh=H446K/7KgdT9qXbPeowydu9cBUFhDnTPMsIkSN1Ikpg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=erBLxwJmNtsgO377ASUWV+mJCit8Le4lCtgYO9UfBquSGVxCgAweHptmmBVCOad/Mm8kzR0BBY0qodKi7WkPLa8D8VVe7EQhW88/VgeTZHPn0pi3HFWY6lpOn4GIyB11+hThoVeeTbq8mbYiZouD26MWNGPUaqAAzfOlUZ9xQOc= 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=lUgimSX3; arc=none smtp.client-ip=209.85.222.180 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="lUgimSX3" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-915bf8800a2so41452585a.0 for ; Sat, 06 Jun 2026 10:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780765418; x=1781370218; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KcV9UXiai8KQeY9VGfmbLVC6lT6RH+nUco+ZyzsOUwM=; b=lUgimSX3eCm3GcgM101hsfVPuKl77uffO2fbRP/Dh8zhIhZ2vfdWlANEGgIEkJqN/v +QnG4bFZM9uTg0C6PYXlbt2cO59lTvhUAfQt/gYiTsCcBfTj3qKYzAftE/POfkaogtEx ryn1f0OpB4cH+qGiZgCE+R82TulF7NCxJ3gBaRM2GRxrxussEQM1nBBdLglAC4rxmP4V Qf36UnwNoal24pJ2MWB+M1uzPo6lFN6qNGPFqPHqKhLLpb6T2AdQpITEaZEkdB5QIx0+ 5hyvpOlja26HHELX0A/uee/zqmBVIyPhSmVeN+M0hXdMwSJs/CQth20vjt9PyzInhvSY qsDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780765418; x=1781370218; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KcV9UXiai8KQeY9VGfmbLVC6lT6RH+nUco+ZyzsOUwM=; b=hzFTpv9WMuWmorvKbP3ohWHiRK0QETRsCqJRnQQ6a4ieG0dQH2TzCPHItolYpfCBCv LN2aB548JPQPxhue1rR07AZJRBvLR8aSHJgu9Dxv1s4bW5+xcshk/l9DjtNbvjUJXVFb VMCZkz3qwmLs8amQyZr8jYUmRcz3ld0cIQCKhbREf90pvRlfvpbBcS8563E7fFkAVSf/ XVTCLV1dPiaIZI9MQjb3vcOek0wTFRIVW+JF6p+ioWDaCaeR6XlrMvRxNO+GWRBGDOXO C+Hx0Vt/qq93mzrQJnwGua65hAiBgwh9KSPcl4mD/thfgeKNWi01hMgErKX3Elj7gBoy SQeQ== X-Forwarded-Encrypted: i=1; AFNElJ+rzF7BY0+mhAcZE4vVos6lsQv8Bd+/THadT1uL3qYamumG67+NrE3BMykA3w+sDfVsAxtFt3PGYCaDQnE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmv/eHGQ7t0A7exDFA7ajNRQu8un29KnKu5x1qFd3aLabSB52c MxqRpq27sgY6u19bsvLl4qI7ZjpuB64z0d0nPTGzCfwb0A16ajQhjjBE X-Gm-Gg: Acq92OEsusra3cYZwyQnDtoZkDvOuzrvgg2IScGQll2TG+DMdUipMUoDO8oGdkQkS/x vvjstup/Ua3vKVeNrQpHfsiNt/zghdE01xisrXXsEQKxC2ZABB7irXmFM6tTwq8AUeuNyLlUbsh kjhyvTveEtZ5fPzZzbNOV8zPpUFql4/KeZ0RUF1ACYqApCmjUKyvOSB2WQ5Jg8L93b/54SVMVsI cWc1S4Pd9ZiiEp3wc1RER2uThK+44z749ELZp6p96nTG5HOdnPk64B0GL4+T5Ljh0K8zVYhAq29 rBghVMIdOtQ6jqMTItvhEpAKq2OKCk2VGlq9ltyVV+JmIRQwjHn+Z3MeG5Hx0Qs1CPoLZ92juld 16hU8jdNSoVwoQzWisHQCXdA+YFDHDvJQJD3pdRO1Ffew0UN+5Oj5pgp+oEm2c2DkVzyp9FGcK1 nwwvsEv5YUID3CLigEAwCsWchGU08DkP7/W8pw7NvbtNwmOoNslSV1c7b6nsjPtvzQ/0Zw+Iu3C +gajUZAn+p05HXLSbZKqPCYB98b3b8= X-Received: by 2002:a05:620a:3910:b0:914:c01e:6f8e with SMTP id af79cd13be357-915a9db9e00mr1538199185a.42.1780765417782; Sat, 06 Jun 2026 10:03:37 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ceccdcb3c5sm117443606d6.21.2026.06.06.10.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 10:03:36 -0700 (PDT) From: Michael Bommarito To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tty: n_gsm: bound the EA scan in gsm_control_rls() Date: Sat, 6 Jun 2026 13:03:23 -0400 Message-ID: <20260606170323.1522340-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gsm_control_rls() walks the control message looking for the end of the EA-encoded address, but it dereferences each byte before checking the remaining length: int len =3D clen; const u8 *dp =3D data; while (gsm_read_ea(&addr, *dp++) =3D=3D 0) { len--; if (len =3D=3D 0) return; } When a malformed RLS control message decodes to a control length of zero, len starts at 0, the loop reads *dp before testing len, len underflows to -1, and the "if (len =3D=3D 0)" test never fires. The scan then keeps reading forward through gsm->buf (kmalloc(MAX_MRU + 1)) until it happens upon a byte whose EA bit is set, reading past the end of the allocation. A two byte DLCI 0 UIH control frame carrying CMD_RLS with an encoded length of zero reaches this from the receive path. KASAN reports a slab-out-of-bounds read in gsm_control_rls() (inlined into gsm_dlci_command()) when the bytes that follow the message in gsm->buf do not terminate the scan before the end of the buffer. The sibling control handlers gsm_control_modem() and gsm_dlci_data() already reject a too short message before walking it; gsm_control_rls() was missed. Bound the EA scan by the remaining length so a zero length message returns without dereferencing past the data. Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- drivers/tty/n_gsm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index c13e050de83b1..4f8f2ce038bc8 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1806,12 +1806,12 @@ static void gsm_control_rls(struct gsm_mux *gsm, co= nst u8 *data, int clen) int len =3D clen; const u8 *dp =3D data; =20 - while (gsm_read_ea(&addr, *dp++) =3D=3D 0) { + while (len > 0) { + if (gsm_read_ea(&addr, *dp++)) + break; len--; - if (len =3D=3D 0) - return; } - /* Must be at least one byte following ea */ + /* Must be at least one byte following the EA */ len--; if (len <=3D 0) return; base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8 --=20 2.53.0