From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383112; b=fimW1dvaDJPxFXdpm1h/3nuPeVjLvukxcoRxwsFh5wmiktjggeEE0nLx0JhmZlrNjB8W ILYvw/Iz5QS4LpjDrAxhO8kouH7sKwYL+KmLPxcU5fYZm86RMU7bj3ILsRR3J5OO0700i 41upth07MS5/eQVlhoWUnxwS/B4hfSzfcwX0/XpdVGM36B4xbdm8ubirNXzgVPlDhuvBO O4zQHL8qbfqMUTMbZsFrj6hH/HdINpMOwjktKyZJp1dzeC/3i18JoVhRaR/Ljgt3kT0By rhThG0HypOHvp/2VQTo8Zns44pWDy0f3QcRWPlTE8zfxxq2H9M3jztuUEaGByPHLm9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383112; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=wHO7PI7CYn5HmmuL9vNPmGX0h0uz5ArTqDJNrijP9LU=; b=DT4B865ke52R4GeSBuNIcA47FJBkM0qAwFfJekGghTwNjO2RHbYUOBUg543SjMXSIi3x 9aCI1stXqeLZVrc9tV3xm2NGe5HfPZwtSB4uXMJwSwq/jd8W8+fE9Xz7Z9/MN8TfzMdF7 r/2tkAnvuFR7/gYm/vokZwEl4Lm8+GiLvaQnam+OZxnT0jEI9YmHOjFrh/AWSSxPDHJeL 7v59Qovc4s6tK0bhqIMX0O83jzxxpjw14M01k1tCSORHPQaDJkO5fzwyR2WMql2tg/8Ua L9WrKV3vr0gOHs7UC/knmsTzTo/x4EpkBVgeZE2wHsLRpuLCCfzbewldO6P1a9cs1ow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dOXN46Ft; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E1B2606A338; Fri, 4 Dec 2026 11:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dOXN46Ft Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8932F1F00A05; Fri, 4 Dec 2026 11:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796383111; bh=wHO7PI7CYn5HmmuL9vNPmGX0h0uz5ArTqDJNrijP9LU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dOXN46FtHTn8BeBEt0KdaMGPGnMEvzcVaXD7knRw7ZJoSMjviD5JVlusYB5o5C9TC tHaJIxnJH1k3mkugd1/V/Vdf25H91hiZIKuhqvUHAzJkpRHj3WVULLoJiyMlxyM1yQ 5scGfWRxcRzGtYe+URBaimydsNDGaPNBCriMB78vLbJ+uKJuXJWbUpM7SPSD6ubT3w SvHzf2UokBiU3mb8u2BIWVuyiAqBq9TP0mzFiVUJwUjhraERfXJfsyy3fw0mbL3dk1 +CyndGG6/N2iMa9nCsVAHRtI+CaC2mkHZULs43tni0+bwgK5f1QccuHyKNNbazIzMQ s0N0yRzhx0f5w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 9/9] greybus: Add Rust UART node driver Reply-To: sashiko-reviews@lists.linux.dev To: "Ayush Singh" , "Jason Kridner" , robertcnelson@gmail.com, "Johan Hovold" , "Alex Elder" , "Greg Kroah-Hartman" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?Qmo=?= =?utf-8?b?w7ZybiBSb3kgQmFyb24=?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?b?T251ciDDlnprYW4=?= , "Eric Biggers" , "Ard Biesheuvel" , "Ayush Singh" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Lorenzo Stoakes" , "Vlastimil Babka" , "Liam R. Howlett" , "Uladzislau Rezki" , "Markus Probst" Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org In-Reply-To: <20261204-gb-uart-transport-v6-9-668b333ae71d@beagleboard.org> References: <20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org> <20261204-gb-uart-transport-v6-9-668b333ae71d@beagleboard.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:18:30 +0000 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] greybus: gb_uart_node: infinite write_all() timeout hangs unbind and UAFs op - [High] greybus: gb_uart_node: Module teardown in Drop crashes or stalls UART RX - [High] greybus: refcount and active-count underflow in gb_operation_request_send() - [Medium] greybus: gb_uart_node: TX buffer undersized for HDLC byte-stuffing - [Medium] greybus: gb_uart_node: premature Module::new() before rx_buf allocation - [Medium] greybus: MTU mismatch between gb-softsvc and GbNode::write() - [Medium] greybus: un-ratelimited dev_warn() flood under SpinLock in HdlcRx::rx() - [Medium] greybus: GbUartNode::init() does not enable optional vbat-supply regulator - [Medium] greybus: unsound Device::as_bound() in GbNode::write() on remove failure - [Low] greybus: HdlcRx::rx() fails to discard HDLC abort sequences - [Low] greybus: per-byte out-of-line crc_ccitt() calls in GbNode::fill_buf() -- commit ffd129080c1e9cab7ecdabc8c7b55016765999a5 Author: Ayush Singh greybus: Add Rust UART node driver This commit adds the gb_uart_node serdev driver for Greybus nodes connected over a UART using HDLC framing, registering each node with the gb-softsvc software SVC. > diff --git a/drivers/greybus/gb_uart_node.rs b/drivers/greybus/gb_uart_no= de.rs > new file mode 100644 > index 0000000000000..b38e776c3e850 > --- /dev/null > +++ b/drivers/greybus/gb_uart_node.rs > @@ -0,0 +1,270 @@ [ ... ] > +struct HdlcRx { > + rx_buf: KVec, > + rx_in_esc: bool, > + rx_overflow: bool, > + sdev: ARef, > + node: gb_softsvc::Module, > +} [Severity: High] Can storing gb_softsvc::Module inside HdlcRx without implementing serdev::Driver::unbind() crash or stall UART RX during unbind? Registration::post_unbind_callback() calls drvdata_obtain(), clearing dev->driver_data to NULL before PrivateData::drop() runs assume_init_drop() and before serdev_device_close() stops UART RX: CPU0 CPU1 ---- ---- post_unbind_callback() drvdata_obtain() dev->driver_data =3D NULL PrivateData::drop() lock(self.active) assume_init_drop() Module::drop() hd.svc_flush() receive_buf_callback() drvdata_borrow() <-- NULL deref serdev_device_close() Even without the NULL dereference, PrivateData::drop() holds self.active.lock() across hd.svc_flush(), blocking receive_buf_callback() from delivering replies to synchronous control requests on svc->wq (such as gb_control_bundle_resume() during gb_module_del()), which stalls teardown until 1000ms timeouts expire. Tearing down gb_softsvc::Module in serdev::Driver::unbind() (stored outside the rx spinlock) runs before drvdata is cleared and without holding self.active. Separately, GbNode::write() invokes AsBusDevice::from_device(), which rust/kernel/device.rs documents as internal and not for driver use, and continues sending UART frames during post_unbind_callback() after unbind() has completed. [ ... ] > + fn frame_finish(&self) -> Result<()> { > + if self.rx_buf.len() < 4 { > + return Err(code::EFAULT); > + } > + > + let crc =3D crc_ccitt(0xffff, &self.rx_buf); > + if crc !=3D HDLC_EXPECTED_CRC { > + dev_warn!(self.sdev.as_ref(), "CRC failed {}", crc); > + return Ok(()); > + } [ ... ] > + fn rx(&mut self, data: &[u8]) -> usize { > + for i in data.iter() { > + match *i { > + HDLC_FRAME =3D> { > + if !self.rx_buf.is_empty() { > + if let Err(e) =3D self.frame_finish() { > + dev_warn!(self.sdev.as_ref(), "bad frame: {e= :?}\n"); > + } > + } > + > + self.rx_buf.clear(); > + self.rx_in_esc =3D false; > + self.rx_overflow =3D false; > + } > + HDLC_ESC =3D> self.rx_in_esc =3D true, [Severity: Low] Should HDLC_FRAME discard the buffer when self.rx_in_esc is true? An HDLC_ESC (0x7D) immediately followed by HDLC_FRAME (0x7E) is an RFC 1662 abort sequence, so calling frame_finish() without checking !self.rx_in_esc emits spurious warnings on every abort and risks delivering truncated data on a 16-bit CRC collision. > + // Skip data if buffer has overflown. > + _ if self.rx_overflow =3D> {} > + _ =3D> { > + let c =3D if self.rx_in_esc { *i ^ HDLC_XOR } else {= *i }; > + self.rx_in_esc =3D false; > + > + if self.rx_buf.push_within_capacity(c).is_err() { > + dev_warn!(self.sdev.as_ref(), "buffer overflow. = Dropping frame"); > + > + self.rx_overflow =3D true; > + self.rx_buf.clear(); > + } > + } [Severity: Medium] Can a noisy or baudrate-mismatched serial peer flood dmesg while preemption is disabled here? GbUartNode::receive() holds SpinLock across guard.rx(data), and the dev_warn! calls in HdlcRx::frame_finish() and HdlcRx::rx() are not ratelimited, so continuous framing errors can stall the serial console and spike scheduling latency. In addition, short frames in frame_finish() return code::EFAULT instead of code::EINVAL or code::EBADMSG, and the CRC and overflow dev_warn! calls omit trailing newlines. [ ... ] > + fn fill_buf(mut crc: u16, data: &[u8], buf: &mut KVec) -> Result= { > + for i in data { > + crc =3D crc_ccitt(crc, &[*i]); > + if *i =3D=3D HDLC_ESC || *i =3D=3D HDLC_FRAME { > + buf.push_within_capacity(HDLC_ESC) > + .map_err(|_| code::E2BIG)?; > + buf.push_within_capacity(i ^ HDLC_XOR) > + .map_err(|_| code::E2BIG)?; > + } else { > + buf.push_within_capacity(*i).map_err(|_| code::E2BIG)?; > + } > + } > + > + Ok(crc) > + } [Severity: Low] Can fill_buf() call crc_ccitt(crc, data) once per slice instead of once per byte? crc_ccitt() is an out-of-line exported C function, so this loop makes up to 510 cross-FFI calls per frame, and GbNode::write() also redundantly computes crc_ccitt() over the two appended CRC bytes only to discard the result. [ ... ] > +impl gb_softsvc::InterfaceOps for GbNode { > + fn write(&self, data: &[u8], cport: u16, gfp_mask: Flags) -> Result<= ()> { > + // SAFETY: `GbNode` only exists while its serdev driver is bound= , so the device is in the > + // `Bound` state for the duration of this call. > + let bound: &serdev::Device =3D > + unsafe { serdev::Device::from_device(self.sdev.as_ref().as_b= ound()) }; [Severity: Medium] Does this Device::as_bound() assumption hold if GB_SVC_TYPE_MODULE_REMOVED fails during unbind? GbHdDriver::message_send() clones Arc out of intf_map and drops the lock before calling intf.write(). On unbind, Svc::module_remove() ignores send_request() errors and cannot detect silent drops from a GFP_ATOMIC allocation failure in gb_operation_create_incoming() or kmalloc_obj() failure in gb_svc_queue_deferred_request(): CPU0 CPU1 ---- ---- GbHdDriver::message_send() intf =3D intf_by_id() PrivateData::drop() Module::drop() send_request(MODULE_REMOVED) (alloc fails, not queued) hd.svc_flush() map_remove() GbNode::write() ttyport_write_buf() test_bit(SERPORT_ACTIVE) =3D=3D 1 serdev_device_close() ttyport_close() tty_release_struct(tty) serport->tty =3D NULL tty->ops->write(tty, ...) <-- UAF If SERPORT_ACTIVE is already cleared before ttyport_write_buf() checks it, ttyport_write_buf() returns 0 and serdev_device_write(..., 0) sleeps forever holding serdev->write_lock. > + // Drop messages which are bigger than what is supported. > + if data.len() > HDLC_MAX_MSG_LEN { > + return Err(code::E2BIG); > + } [Severity: Medium] Does this 504-byte limit mismatch the MTU advertised by gb-softsvc? GreybusSoftSvc::init() registers the host device with GB_OPERATION_SIZE_MAX (65535 bytes), which protocol drivers such as gb_uart_probe() query via gb_operation_get_payload_size_max(). Any protocol transfer larger than 504 bytes will therefore fail at runtime with -E2BIG instead of being segmented to the transport MTU. > + let mut buf =3D KVec::with_capacity(HDLC_MAX_FRAME_LEN, gfp_mask= )?; [Severity: Medium] Is buf undersized for HDLC byte-stuffing? HDLC_MAX_MSG_LEN is 504 unescaped bytes, but fill_buf() doubles every 0x7D and 0x7E byte in the header, CPort ID, payload, and CRC, requiring up to 2 + 2 * (6 + data.len()) bytes (1020 bytes for a 504-byte message). Valid messages up to HDLC_MAX_MSG_LEN will fail spuriously with -E2BIG whenever byte-stuffing pushes the wire frame past 512 bytes, while small messages always allocate 512 bytes instead of sizing to the worst-case escaped length for data.len() as hdlc_encoded_length() in drivers/greybus/gb-beagleplay.c does. [ ... ] > + // A short count means the wait was interrupted by a signal afte= r part of the frame was > + // accepted. The rest is never sent; the receiver drops the trun= cated frame on the next > + // flag, but the message itself was not sent. > + if bound.write_all(&buf, 0)? !=3D buf.len() { > + return Err(code::EINTR); > + } [Severity: High] Can passing timeout 0 to bound.write_all() hang unbind permanently if the UART stops draining? serdev_device_write() converts timeout 0 to MAX_SCHEDULE_TIMEOUT while holding serdev->write_lock, and GbHdDriver::message_cancel() is a no-op. Because Greybus sends messages from signal-less kernel workqueues (svc->wq, connection->wq), a stalled UART blocks serdev_device_write() indefinitely, so unbind deadlocks forever in gb_operation_cancel() waiting for operation->active to drop before serdev_device_close() can run. Holding serdev->write_lock synchronously also serializes concurrent asynchronous Greybus operations. [Severity: High] Can bound.write_all(&buf, 0) sleeping interruptibly inside gb_message_send() cause an active-count underflow and use-after-free in gb_operation_request_send()? gb_operation_request_send() takes two active counts and two references and arms operation->timer before calling gb_message_send(): CPU0 CPU1 ---- ---- gb_operation_request_send() gb_operation_get() x2 __gb_operation_get_active(2) add_timer(&operation->timer) gb_message_send() GbNode::write() bound.write_all(&buf, 0) gb_operation_timeout() (sleeps interruptibly) queue gb_operation_work() gb_operation_put_active() gb_operation_put() (signal -> -EINTR) err_put_active: gb_operation_put_active() x2 <-- active underflows to -1 gb_operation_put() x2 <-- extra put / use-after-free The same three-puts-for-two-gets underflow occurs if gb_operation_cancel() queues gb_operation_work() while write_all() is blocked and later returns an error, leaving operation->active non-zero (hanging gb_operation_cancel()) and dropping an extra reference on struct gb_operation. [ ... ] > +impl GbUartNode { > + fn init(sdev: &serdev::Device>) -> Result { > + if sdev > + .set_baudrate( > + sdev.as_ref() > + .fwnode() > + .and_then(|fwnode| fwnode.property_read(c"current-sp= eed").optional()) > + .unwrap_or(115200), > + ) > + .is_err() > + { > + return Err(EINVAL); > + } > + sdev.set_flow_control(false); > + sdev.set_parity(serdev::Parity::None)?; [Severity: Medium] Should GbUartNode::init() enable the optional vbat-supply regulator? Documentation/devicetree/bindings/beagle/beagle,beagleconnect-freedom.yaml declares vbat-supply for beagle,beagleconnect-freedom. Without enabling it (for example via kernel::regulator::devm_enable_optional()), boards with a controllable vbat-supply rail not marked regulator-always-on can leave the MCU unpowered or have the rail disabled at regulator_init_complete(), and -EPROBE_DEFER will not be honored. > + let node =3D gb_softsvc::Module::new(&[Arc::new(GbNode::new(sdev= .into()), GFP_KERNEL)?])?; > + > + HdlcRx::new(sdev.into(), node) [Severity: Medium] Should rx_buf be allocated before calling gb_softsvc::Module::new()? Adapter::probe_callback() holds private_data.active.lock() across probe, blocking UART RX delivery. If KVec::with_capacity() fails with -ENOMEM in HdlcRx::new(), dropping node calls hd.svc_flush() while the queued GB_SVC_TYPE_MODULE_INSERTED work transiently publishes the module and waits for UART control replies that cannot be delivered, stalling probe error unwinding until the 1000ms Greybus timeout expires. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-gb-uart-tr= ansport-v6-0-668b333ae71d@beagleboard.org?part=3D9