From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB7891CF80 for ; Sun, 17 Mar 2024 18:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710699347; cv=none; b=Lozvs1zD7P/WJdA/7t9DR44iuEEcFWCFvEGLYpoLNWRussJshMITcr8YKedIq5sk0gl0Op38UHTU3x7S98BRohzcMUjUnUkBMNj0/YWG+fWCzSwPNZeFrbeaHHBkg0RvApYnRdnO6hvCA3QqK2pBZazga747UQv5g7MXt+p3MLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710699347; c=relaxed/simple; bh=4Plx07fYtwyhH3RbdoZN6JxQP7PRMRPO743o/7Rgk2E=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=UXD5Zoopqu8+W8wSGNL5d1qBqnIGmAl3jtWXtFpE6JKdKveDCeEjOnc5KkZGeKyC/7aG18UwOd/yWFkiru04sf+DeVcPul8jk11jMzpDEJ8VaI2YQ6Z2FTZTBF0V1Fo3fWMoY9TJsm3PC0vX1OrinFneGC0/fwe+M7tVzXUmiXs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net; spf=pass smtp.mailfrom=jannau.net; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b=b5nr8hp+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RbG7DBr9; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jannau.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b="b5nr8hp+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RbG7DBr9" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C7980114009F; Sun, 17 Mar 2024 14:15:42 -0400 (EDT) Received: from imap53 ([10.202.2.103]) by compute1.internal (MEProxy); Sun, 17 Mar 2024 14:15:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jannau.net; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1710699342; x=1710785742; bh=w1fwjkNziD 4xEBR+Pb5UnFJ4ELEgg23YqrQzysmRZ90=; b=b5nr8hp+BwpQ2OBlrvnDnxO9CJ S1HdjtzchbPACi6pBl84MI9mMkN/du05RNKpOii1NO4kFvuuRQaBRnXt1l4vwVdl h0b9hozEiSt//uNADWbugr/r8VmYkx6tVLP/Y+lX5tzQlk2UuseQGWXzc7tfeSMU aIYdcxsUujvBFkxeP7tjpz9hGAZsf9kEl6dlokg6VIbewEjr5pBJeTlYvXQrto+b 39A5WIFx/IeJPS9iuj2+/WldoDOzapUVPL5c8IxE9bFmEI0SxI1YFKqcYEbeKfpR bt/AjzVo0HVh40kfouryPG1SCCVNc8IvvOryg0cbWI6I+VUzzVq778VP9coA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1710699342; x=1710785742; bh=w1fwjkNziD4xEBR+Pb5UnFJ4ELEg g23YqrQzysmRZ90=; b=RbG7DBr9gQL3qGYsinHbNngoi8EIpniSoNTgJV6m2QWU CDUw0rXjw96Dw/9ZgSijG9p6RAAqxyDEHj8tkj1DM6MUs9PrDnxlHumJN9fpAj9B SH4s78THll/6ZpQwXIi+H7w7MSzSV6zHEiiThai+dV0rgzRaLvU7iNFhljQlLSLW h7ROf0EwAGjH1wS2pNWGUY9rI2N8oXV+uT90zFY1v8ImIdifrKVFM80eVWEINcWZ ZK4tvdlB1aAznZYtivnMxfsOoK3OG2iZvaEG4Qc2TFEz1g9TlbZbBZhlAif5H1GJ xcHjjLpIsKd9zsd7Igp6Ge6+4BvrJNhiVsCno1RYpw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeehgdekjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdflrghn nhgvucfirhhunhgruhdfuceojhesjhgrnhhnrghurdhnvghtqeenucggtffrrghtthgvrh hnpefhheeiveffvddtteeugfeuudekfeetudethffhfefhfefhkeeuhfeffeetjefhieen ucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhesjhgrnhhnrghurdhnvght X-ME-Proxy: Feedback-ID: i47b949f6:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 67B7D36400AB; Sun, 17 Mar 2024 14:15:42 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-300-gdee1775a43-fm-20240315.001-gdee1775a Precedence: bulk X-Mailing-List: asahi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <970e9686-4bcc-4cda-95b7-e5cb470682b0@app.fastmail.com> In-Reply-To: <22be2258-ff20-4e62-a169-4748cbba4904@denx.de> References: <20240317-asahi-keyboards-v2-0-d3f4b8384f68@jannau.net> <20240317-asahi-keyboards-v2-4-d3f4b8384f68@jannau.net> <22be2258-ff20-4e62-a169-4748cbba4904@denx.de> Date: Sun, 17 Mar 2024 19:15:22 +0100 From: "Janne Grunau" To: "Marek Vasut" , "Bin Meng" , "Tom Rini" , "Simon Glass" , "Joe Hershberger" Cc: u-boot@lists.denx.de, asahi@lists.linux.dev Subject: Re: [PATCH v2 4/6] usb: Add environment based device blocklist Content-Type: text/plain Hej, On Sun, Mar 17, 2024, at 17:18, Marek Vasut wrote: > On 3/17/24 12:07 PM, Janne Grunau via B4 Relay wrote: >> From: Janne Grunau >> >> Add the environment variable "usb_blocklist" to prevent USB devices >> listed in it from being used. This allows to ignore devices which >> trigger bugs in u-boot's USB stack or are undesirable for other reasons. >> Devices emulating keyboards are one example. U-boot currently supports >> only one USB keyboard device. Most commonly, people run into this with >> Yubikeys, so let's ignore those in the default environment. >> >> Based on previous USB keyboard specific patches for the same purpose. >> >> Link: https://lore.kernel.org/u-boot/7ab604fb-0fec-4f5e-8708-7a3a7e2cb568@denx.de/ >> Signed-off-by: Janne Grunau >> --- >> common/usb.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ >> doc/usage/environment.rst | 12 ++++++++++ >> include/env_default.h | 11 ++++++++++ >> 3 files changed, 79 insertions(+) >> >> diff --git a/common/usb.c b/common/usb.c >> index 836506dcd9..73af5be066 100644 >> --- a/common/usb.c >> +++ b/common/usb.c >> @@ -1084,6 +1084,57 @@ static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read, >> return 0; >> } >> >> +static int usb_blocklist_parse_error(const char *blocklist, size_t pos) >> +{ >> + printf("usb_blocklist parse error at char %zu in \"%s\"\n", pos, >> + blocklist); >> + return 0; > > This could be static void without return 0 at the end. the return is there to break out of the while loop on parsing errors in a single statement. This probably won't be necessary after using strsep and sscanf in the parsing function but see below. >> +} >> + >> +static int usb_device_is_blocked(u16 id_vendor, u16 id_product) >> +{ >> + ulong vid, pid; >> + char *end; >> + const char *block_str = env_get("usb_blocklist"); >> + const char *cur = block_str; >> + >> + /* parse "usb_blocklist" strictly */ >> + while (cur && cur[0] != '\0') { > > Have a look at strsep() , namely strsep(block_str, ","); This will split > the string up for you at "," delimiters. > > Example is in drivers/dfu/dfu.c dfu_config_interfaces() . strsep() is probably a good idea even if it alone won't make the code that much simpler for strict parsing. > And then, on each token, you can try and run sscanf(token, "%04x:%04x", > vid, pid);, that will parse the token format for you. See e.g. > test/lib/sscanf.c for further examples. > > That should simplify the parsing a lot. It would but sscanf() is optional and is only selected by CONFIG_XEN so I assumed there would be concerns over binary size increase if USB_HOST would require sscanf. Janne