From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 E6F562E6CA6 for ; Tue, 4 Aug 2026 01:47:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785808049; cv=none; b=pLryn86Ylv6i2V9ZP3NzWFFo5oo1o6OyMIpJH5wyMIfnwr9AOkVTJbj5iQBekF6VwsBnAPHxOhjyruyeIeDev8yRT3ddk7iF8ILumLHF/+Y0uRkFR6j2B5eIaaSPnMkqdKfKsaqrfkI8k5llFU3+/Vvo7SCPPVA/6RYNlm7krN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785808049; c=relaxed/simple; bh=AlNJyTnQ+/4lHutdhmK/M1oi40ml9td+PGCVh1fLE0s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PuO4OyAkOhO7F7NdJJBbQx+2Uu1LiqIuu4FMx8+zCSgNIMpPzeSrP9oGhjmHxxmFVUjuJMQ57Uw8MFVdZqMy1+mlaDAGzkGnP9978LFRWYMPrfcuYvSZag0BK3m2V7HDtJL/+K26V5atSd//WTIX2zMh2PIh0DVwQOuSbw4xARQ= 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=FiTMHqYJ; arc=none smtp.client-ip=209.85.214.178 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="FiTMHqYJ" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2d01663d816so31529515ad.1 for ; Mon, 03 Aug 2026 18:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785808047; x=1786412847; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=PJCid5QSTmLmbjEgfYWoSErYZcDK6ekrRH1upJJmdlQ=; b=FiTMHqYJdS5M5olrNnWK10C0QLdjACPXEQFwc/tpT4CqGEHFD25t7hbBTZiNmhdTNX 2AaXv9jCZ2CO7+F0npeTkxGBIFx8+6xlgj6atIGpR+U0gdreapWg6CSVs3eKLKonKtil 6edysg0sriKLF6Q/jN1Ac4AL8mGGo05yHRX8316F0BzfS/kqjAvKmrvDGxdwuqaNMq4y az7AuDoAV/YVoChXclV9mWRFw8ZfyNVjKZIxhzJchTbviXxMJ47ONVatoRWSIFpWL1w9 EnxoYPokdQIo9f3+jb+bD/F06QmlUKMzv2aOLJd5ShCOH0iCTYUXHVwbQ+KjYGo3170h FIOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785808047; x=1786412847; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=PJCid5QSTmLmbjEgfYWoSErYZcDK6ekrRH1upJJmdlQ=; b=itAQYWT/UJmMLETPzgsLxYidArf1NLD+u07R8QNQ1TLwdBvuoUXFzYAvvpzZhqiyhe 6NzJXASg1kD7Ggvs5zNP4YuCW79seHuH+J3/Km/bSFs6aeWMdUYOa2txZJB4w3SBWUAN Q7dhQ49KNWhiZb3bAQTGYxw3PNXPuJtD9F9QN/f10Q7hdY0E7l9LNJ+W1y7I1mzNLVIj 0oHWPnnXQko2BEw0kzNNMUVIwsYyxf1xrqAycKLIflEgHYEs0OmbZxj7sf0O7/MT1mTT WDY0msL1gzt7WtDvPqJzeORxisCPEHd3kRT53/cP9who9ZV8Z1VXC0rx1J50APNCqfqH 46Jw== X-Forwarded-Encrypted: i=1; AHgh+RrLLthlKzSV14RKE07Kg+ec4hJKXO8BuqDmd1RCne4I6d6aaEpaakmtM8xMNagnnepkEIjeqwIN+EuqyU4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzegr6XFwwgZ7yGfatzle6C5Qrfd4mQr646HPe8djR7hCw3eoAh JhKAhzssMRhtCaSDtGA06JDGWWfLLE44jD6idA9KHD9LC+QytaaQeJDF X-Gm-Gg: AR+sD11PH14Kcu0PqkgpxF3EbvGj8vx/p1+qKHvVQja4OFgUyMLp9MShbccTViE8sVA NJp5fJCVPQB6RXQgbRfKq5lzyK4pdD31yL9JSzKbrMpzjUDsHyXQGbRlvTBF9239x3MoSZQ+igR 5iPPpKluLPW7ZMDIWP84sPoKS1B4j8IdapBjnhP9jM6Oc0Y1ITkCEjavG3MQjyw7mDdIMoB8qr1 xxV0ya5ommhfB/vqVd2qCegMLRKxMiUc2Lk+CU2BVfzG1ujan3F1V9RHA5s61jyXFerNRbpP5Yt fpuwXPofSwuGZRgRibiciWHPxfR4WatqyD7gY2BnJjYbj0Z8l8vkDLh/oBP3nvqt4xEhVcbRx/H qsgYDQT8giGFwL62NzteBL2C9tLVw752XV5vX9ZNPSstoxrU6Ae6g/BuiI9yo5C+7l45KWAvzt6 rySHPEBfbYMI1JhLndiVEV56RM9Htj4gIadEZoVR6eu7XPV3hCAKJ0HngNavoeue1is9YG748RG 2EwljjZD9hboQhrHqpe5MC+q8jjrg== X-Received: by 2002:a17:903:3c27:b0:2c0:b6c7:227e with SMTP id d9443c01a7336-2d05219f8fcmr126095735ad.5.1785808047215; Mon, 03 Aug 2026 18:47:27 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e04456dsm39860651eec.14.2026.08.03.18.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 18:47:26 -0700 (PDT) Date: Mon, 3 Aug 2026 18:47:23 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: David Rheinsberg , Peter Hutterer , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: uinput/uhid - disallow control characters in phys paths Message-ID: References: <20260717-wip-uinput-sanitize-phys-v1-1-f6459542ce4b@who-t.net> <1ed3a0b5-db39-4a82-b549-0ed7e2cf89c2@app.fastmail.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=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Aug 03, 2026 at 09:58:35PM +0200, Jiri Kosina wrote: > On Fri, 24 Jul 2026, David Rheinsberg wrote: > > > > There is no good reason to support those, no physical device will ever > > > produce those. Allowing \n in phys previously triggered CVE-2026-50292 > > > in libinput - there the PHYS udev property value was used as part of > > > another udev property value. The linebreak then caused the property > > > to be split across two lines, allowing uinput devices to inject > > > malicious properties. While the bug is squarely inlibinput's court > > > there still isn't a good reason for control characters in uinput/uhid. > > > > > > Signed-off-by: Peter Hutterer > > > --- > > > drivers/hid/uhid.c | 1 + > > > drivers/input/misc/uinput.c | 1 + > > > include/linux/input.h | 15 +++++++++++++++ > > > 3 files changed, 17 insertions(+) > > > > > > diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c > > > index 37b60c3aaf66..baf1fe8290f7 100644 > > > --- a/drivers/hid/uhid.c > > > +++ b/drivers/hid/uhid.c > > > @@ -513,16 +513,17 @@ static int uhid_dev_create2(struct uhid_device *uhid, > > > ret = PTR_ERR(hid); > > > goto err_free; > > > } > > > > > > BUILD_BUG_ON(sizeof(hid->name) != sizeof(ev->u.create2.name)); > > > strscpy(hid->name, ev->u.create2.name, sizeof(hid->name)); > > > BUILD_BUG_ON(sizeof(hid->phys) != sizeof(ev->u.create2.phys)); > > > strscpy(hid->phys, ev->u.create2.phys, sizeof(hid->phys)); > > > + input_sanitize_phys(hid->phys); > > > BUILD_BUG_ON(sizeof(hid->uniq) != sizeof(ev->u.create2.uniq)); > > > strscpy(hid->uniq, ev->u.create2.uniq, sizeof(hid->uniq)); > > > > > > hid->ll_driver = &uhid_hid_driver; > > > hid->bus = ev->u.create2.bus; > > > hid->vendor = ev->u.create2.vendor; > > > hid->product = ev->u.create2.product; > > > hid->version = ev->u.create2.version; > > > diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c > > > index d32fa4b508fc..70fe4f3e73bf 100644 > > > --- a/drivers/input/misc/uinput.c > > > +++ b/drivers/input/misc/uinput.c > > > @@ -998,16 +998,17 @@ static long uinput_ioctl_handler(struct file > > > *file, unsigned int cmd, > > > > > > phys = strndup_user(p, 1024); > > > if (IS_ERR(phys)) { > > > retval = PTR_ERR(phys); > > > goto out; > > > } > > > > > > kfree(udev->dev->phys); > > > + input_sanitize_phys(phys); > > > udev->dev->phys = phys; > > > goto out; > > > > > > case UI_BEGIN_FF_UPLOAD: > > > retval = uinput_ff_upload_from_user(p, &ff_up); > > > if (retval) > > > goto out; > > > > > > diff --git a/include/linux/input.h b/include/linux/input.h > > > index 76f7aa226202..6c182f5c783f 100644 > > > --- a/include/linux/input.h > > > +++ b/include/linux/input.h > > > @@ -527,16 +527,31 @@ int input_set_keycode(struct input_dev *dev, > > > > > > bool input_match_device_id(const struct input_dev *dev, > > > const struct input_device_id *id); > > > > > > void input_enable_softrepeat(struct input_dev *dev, int delay, int period); > > > > > > bool input_device_enabled(struct input_dev *dev); > > > > > > +/** > > > + * input_sanitize_phys - replace invalid characters in a phys string > > > + * @phys: the phys path to sanitize (modified in place) > > > + * > > > + * Replaces any control characters and non-ASCII characters with '?'. > > > + **/ > > > +static inline void input_sanitize_phys(char *phys) > > > +{ > > > + char *p; > > > + > > > + for (p = phys; *p; p++) > > > + if (*p < 0x20 || *p > 0x7e) > > > + *p = '?'; > > > +} > > > + > > > > Reviewed-by: David Rheinsberg > > > > I would also be fine to just reject them in uinput, but I guess this is the less intrusive option. > > Thanks for the fix. > > Dmitry, can you please Ack the above addition to input.h? Jiri, as I mentioned I believe that if we need to sanitize phys we should also sanitize other fields, especially given that they can be set by userspace. I also wonder why it needs to be inline? And what is wrong with using isprint() here? Thanks. -- Dmitry