From patchwork Thu Apr 11 17:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 787967 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp356724wrm; Thu, 11 Apr 2024 10:53:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZfOFjXQYirhVfewohg8TrIUR5PjQI1Wp2Ktl0xyoxVcXIk5y3FUqPRg0TnUBiZBWqHY+T7Rfhg2RKsxirptxt X-Google-Smtp-Source: AGHT+IGUeK3eJIMgtvmFvAJSyGLmJPez8AEatpYPSCqO/T0u7Q45ABzR3pe9NEEwfZI+fHxPI3FU X-Received: by 2002:ac2:4db6:0:b0:513:e909:f234 with SMTP id h22-20020ac24db6000000b00513e909f234mr241968lfe.57.1712857994377; Thu, 11 Apr 2024 10:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712857994; cv=none; d=google.com; s=arc-20160816; b=A1oCZQpz3+bQP02zJJcKQ/VoC4+PCQMwgw0rFWFFMU2WQMgyCsf/FD6wEx9p2QZzHS ucZ5/RB3Odx706sh+RHY85Zi21aGM2wEMSQ/7AlUklVXUDGlXBRbz6FeD6GxstwPxwI0 oAb03XGDOmU1H8paebk37m9+4UBDKfI4u0aLVAetKfuUSkqz0kyePBmGVg5N8OXvT1W5 kWl1VOZeZHY05hxoeCgXDCZTV68cy1XpW7mYi6ReNqWhnKeU3pDnKDDnGfRI1Y4tyqNP s+PJbQ2w5MH+Z8WYZW15qvszqr8jly4p/BEHFOrASRW6X6Tt7hWVLqRkdcT00vxSwtar RgrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=1AeII3r5MVcCQpaq1ln/8s1eOrE8HbiWZ4EfXHkUwfc=; fh=E3DCFfZytk827PcVifWhcULZAn0cKzkxa1NwXsU4xsc=; b=Q7nAXsruE3+cWpSpuaUC9xQ4W8D2qvJoNrwc32FOo9X3OAlqa+HDE89g87gQbleMgx jCxBDyn+xV6sY+DBnSaUmoDPN0fpfbReUogqlh0JuKgmJc9RiAUM1irhRgjbnF2PgSHp dm3ROB1TYXmcobEQnvJkCjTNBkBzOUyexJDiSm2dudy0cy+HgSCpITe+SMardrUA/UI4 1Z8X7b3mapEuDiCfqZKN5JClChiqXU0YBkXHBAu1RWJilWYAwb76lD+CDI6lUBm/5ibH /0mgTa6ELx0UIBIZXOle89xcIoUJNQ9+dWLHFQvmlyBvlARXbNpBhaM7g1PBFgZjYrYw L0/A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LF/9AmRY"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id nb11-20020a1709071c8b00b00a52228d8675si824912ejc.44.2024.04.11.10.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:53:14 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LF/9AmRY"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EE52E881F6; Thu, 11 Apr 2024 19:53:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LF/9AmRY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 130C3881FC; Thu, 11 Apr 2024 19:53:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0BC6A881F1 for ; Thu, 11 Apr 2024 19:53:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2d9fe2b37acso362961fa.2 for ; Thu, 11 Apr 2024 10:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712857988; x=1713462788; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1AeII3r5MVcCQpaq1ln/8s1eOrE8HbiWZ4EfXHkUwfc=; b=LF/9AmRYQNSzsjf82hqELCEC7VbVioda9nI9/3KVwFshQvdUdZZJO7LeqYBtXgxvi9 uyntU8XvnOomTIDDfq9K4mqDv1qoZZ1Yje20RNxSV7fe+0zo3daqUrHyeHD+Muz3F9R0 aqQn4h1e9ZJsvTsCTVASj9+UPGRsYZLWq6UVfpCYxGLo/qAYLl6H4n1YDiG8RH4bljlK Nr+CHqO6u/uc3vaILp3W4WZTn8m3pvwEdfDa9/xOXymNC3xGX9lvEexmh++suuBXxe35 XIrDTB9BELWAoihf+gvNHUxifR6ug82XFtZA/nrJk3iCuj7/6I9tkUc5Bc9MLzJvXzX+ gtEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712857988; x=1713462788; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1AeII3r5MVcCQpaq1ln/8s1eOrE8HbiWZ4EfXHkUwfc=; b=rZtzJg5lJeg8I4/sZ3CJkQGGyQaWJ5TyH1rrceRgtSVBZfDqMVBl4upYTkhnHY8k/2 oJCrDFzcZz8UtT+QpBes06xCgQH9+pGwo8w9km9mFDFZzrjIV4GU2IYmPyLwcCLwX1Jv uPBoEDv5KSHrb+b54Y8aabuv0Q1jHoBfFytCmCLCd+Rslm7G5RSfF+gJS2v7FF7Tvhlx n71a6NVLSFQlh2j2fDkn3YISPSXNfwf5OLFoBelMtTHiEO1pv6j3C7IxamA2ZCQIWnaX zdowLk7MM624eddcgOC6thZ5DrSUiCtca1Gh3jbJwYqdiOhbjE/oI3zRYMyQ5MU914Y+ WtpA== X-Gm-Message-State: AOJu0YzqJv6d0lDfSjlFjRmWLrt/7grfRyIwT66X9Bogyj6BGy5GZyFw cOylz6nita6HaspN7iOsCO40mJOhefaIgn2a2uoS6UCkBDm57ZKTHw38RYQ2wOA= X-Received: by 2002:a05:6512:485c:b0:513:bc95:50c3 with SMTP id ep28-20020a056512485c00b00513bc9550c3mr302566lfb.12.1712857988153; Thu, 11 Apr 2024 10:53:08 -0700 (PDT) Received: from cymric.caleb.rex.connolly.tech ([2a02:8109:aa0d:be00::570d]) by smtp.gmail.com with ESMTPSA id j7-20020a170906254700b00a4655513f0bsm951925ejb.88.2024.04.11.10.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:53:07 -0700 (PDT) From: Caleb Connolly To: Caleb Connolly , Dzmitry Sankouski , Simon Glass , Tom Rini Cc: u-boot@lists.denx.de Subject: [PATCH] input: button_kbd: gracefully handle buttons that fail probe Date: Thu, 11 Apr 2024 19:52:37 +0200 Message-ID: <20240411175244.937795-1-caleb.connolly@linaro.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean If a button device fails to probe, it will still be added to the uclass device list, and therefore will still be iterated over in button_read_keys() resulting in a UAF on the buttons private data. Resolve this by unbinding button devices that aren't active after probing, and print a warning so it's clear that the button is broken. Fixes: e8779962898e ("dm: input: add button_kbd driver") Signed-off-by: Caleb Connolly --- drivers/input/button_kbd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/input/button_kbd.c b/drivers/input/button_kbd.c index 74fadfca8bb8..c73d3b18be9c 100644 --- a/drivers/input/button_kbd.c +++ b/drivers/input/button_kbd.c @@ -33,9 +33,10 @@ struct button_kbd_priv { static int button_kbd_start(struct udevice *dev) { struct button_kbd_priv *priv = dev_get_priv(dev); int i = 0; - struct udevice *button_gpio_devp; + struct udevice *button_gpio_devp, *next_devp; + struct uclass *uc; uclass_foreach_dev_probe(UCLASS_BUTTON, button_gpio_devp) { struct button_uc_plat *uc_plat = dev_get_uclass_plat(button_gpio_devp); /* Ignore the top-level button node */ @@ -45,8 +46,23 @@ static int button_kbd_start(struct udevice *dev) uc_plat->label, i, button_gpio_devp->name); i++; } + if (uclass_get(UCLASS_BUTTON, &uc)) + return -ENOENT; + + /* + * Unbind any buttons that failed to probe so we don't iterate over + * them when polling. + */ + uclass_foreach_dev_safe(button_gpio_devp, next_devp, uc) { + if (!(dev_get_flags(button_gpio_devp) & DM_FLAG_ACTIVATED)) { + log_warning("Button %s failed to probe\n", + button_gpio_devp->name); + device_unbind(button_gpio_devp); + } + } + priv->button_size = i; priv->old_state = calloc(i, sizeof(int)); return 0;