Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp917576lqo; Fri, 17 May 2024 05:49:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2Ps7UbzDl6RJ9rk2aDhVWqYDY/mZHSLJWgBmz4/TlbfPoKjgJIBExiidOIWQqqDYKll7O/4FKCqhitd3YFK2km5T/+cpCnW7DHPfoFg== X-Google-Smtp-Source: AGHT+IGJKR1q1qcM6Kpc/76rgXP8IL2P7nzaE6Nsw2u79dv28tsZ1mbta+fCpApTkvaGO4E09DUo X-Received: by 2002:a05:6a21:819f:b0:1b0:2184:c0a2 with SMTP id adf61e73a8af0-1b02184c28dmr9187297637.6.1715950165608; Fri, 17 May 2024 05:49:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715950165; cv=pass; d=google.com; s=arc-20160816; b=aks+vk7NML4JCEt07a5E37tO/2JATdVhc45AYIAR4dli2IIOXg6wl3uyieaGaSPV3P dVj58gXVGYYPg8fslC89sCdDjDAL1PmYUGcG9e6b+QtmDK3PkTQB54hqkzkhrxS4mrn1 clI8WzOkPYp4ljgH++4egwfEfmJ1f0V7S369o6lthmjd1Us3Q1xLGLzh1wmjZzIG+FsZ uYOu1uJpQUvst52W3UKpmwOZ81724lr8gqtd22nfOH09nz/rK31Ymm6WCj0cisrj48vl UB3ArDSo/Kyxghq9BdC0urdexykgV88lwsX5gjIRJQ8QYCkDzDBLa8Xsn8maXjyWdnIR J1mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nfAjld03szr0Dl9MxPW24cnUDUMLGuL4kllMrODJJg4=; fh=F9V1QcnYjHqepglXH/zBxlpu31QXxrH6xKG0oqFYDzs=; b=dt86VdTvB5Zv7j6yD2ZgU1a76w6cIJYBNAvS8Qweq1mw0GVOfT51zQQeQUEwfCZO3z zaCrvVNW1VdFXh0238VcGCfGkxgVo8y7XGlJg+Ecy466ET5WmZW+cChi9RQ+IA7Fsgxb IbzT0vWWHl4qx4p6UnOeIWddeeaf+AXhJh94Cmzq5O+482gHg66mMgYtkISlPVe/PPMt mje29zeNnJysualGL0G4obWEKn88IVzwY8PvOnFXHSCLq0hHbhvx7yyVwLiez9WRkV1d FJTtFY/xxqNGFKbzpwOuu6GhP/i7q5KqtMRBAk05fW3DJRCt2Y3Znv3ZmQpv5md2Gva8 I0GA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g93ddjKa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182106-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6479a59ce9asi4341417a12.526.2024.05.17.05.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 05:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182106-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g93ddjKa; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182106-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 495C82838B9 for ; Fri, 17 May 2024 12:49:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADE604F1E4; Fri, 17 May 2024 12:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g93ddjKa" Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 80E5A481C7; Fri, 17 May 2024 12:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715950158; cv=none; b=lsMJ3cKFqbeydFQd4etv9N6CUHSqJCWWyN88rHWZN67NJ8/fWd4++u5PxUf7GwjwG0pdHF8ZgKpwAK9l4RwbdJ106ELLR81S+/VS2LsFaVob6467iqC+SIRLk/zFUAxvM94p8ciPV+Ee/cSJEaV9XLymhHISDmsLw8lUgEkXfsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715950158; c=relaxed/simple; bh=dFdaHos0UdTJQEbHjqSGh82k3xs2CBpBqd+kZi11i8Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UPtUrxiQrbsgKv4XeEQK2te7u9uZWU+jHh6Dz04tw+oxnVOEI9/WBxbtI+wLW3tNIfJSam+tFfNTj8NHIsLJvQW7uFHi8WS8cvfGNhoD2+radt0juEFWJMbe6kikjLKKmus2lbt3DiBXeQ8xyaOWRElzdlPrzgq6HYkE873OaXY= 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=g93ddjKa; arc=none smtp.client-ip=209.85.216.45 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 Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2b9cdbd6da9so926857a91.1; Fri, 17 May 2024 05:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715950157; x=1716554957; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=nfAjld03szr0Dl9MxPW24cnUDUMLGuL4kllMrODJJg4=; b=g93ddjKaCTQAVH5AsNVJu8SB19p+8X8UY1vzcIXIOI6vUr/b1tE9nKfuGoRIrKqMS+ b7EVC72l4ndE7dA5FvfzeSaxGf/4Nib1W9YFwtasI8WqLcfIB2+AqYgkxfxZ5lSLkmTw q6f73kRRKjcBhbpRYuoUfCB1OlSH+RfcA1i0AIj0xcP3pDqH0+Y6p0wbAdSzEn9l/ffa /s08TFsFbR+Zw/eXs5MVZSvHy1f7zV4WhTlUpIvw0sPVS2ZVQ8zibXlqsxb+iSEk0ImQ hhoP6hlYlCPvyIw+NOJA9QqamHGEw9YcbXqj+qL7KK7qavw+oMTpZO0iwY36h36UWHSE Dk3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715950157; x=1716554957; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nfAjld03szr0Dl9MxPW24cnUDUMLGuL4kllMrODJJg4=; b=DjqSevAX2uhjjyLiqbSWZ78Gg2gPFdzx9yCZEMWsF5TjquSzl2qxzN8WmosqyhzXC3 je9s+4kshb1909h3RZwVp0lQMVvUPyiplsmdJMHXQNTddZkmZrD9Eoz1qgwWlucVt8Fu czROL/FHsom0Dl9KP5vu2CKkOzAeAhhqHAhY/CRPdCySuJkA6Bc05OpaO8tqwe4n2W68 WRHrLOsUX1xIt5BZ/tPqTEEgI7dGfVWR5IE4+inYNyd4f1CURAjGy/h6eUFMVViARMOg wCWyv/wbM9UQumSX2YBzEht8gEt7jpmmNrAUMnibZtzvPviK5rcQy47IPq5/36pElZei KZ/g== X-Forwarded-Encrypted: i=1; AJvYcCVNs+x1ZYicKUgG3zCl/2RyxkMREFQMeQo8LdCaUTmEKEkBLfNWzhcKi5Mw4enCVRFB5Cmb6UUc8GGrk9IjrvgV4QuBKpG6JvZaJ827nKP3hfFLjCY3L+JZZCY9ka/ATYPnX+XNnvtReQ== X-Gm-Message-State: AOJu0YwG2k0Xe4noWSRg3FXrWrTkoil8+kh0g7bT8HvvUm06OfVza+kP iDbTJLLne3NkF1iWZbuOgoYeQcv4vSoRB1h20vH1h2OQXWAjCY4m X-Received: by 2002:a17:90a:a108:b0:2b0:e497:56f2 with SMTP id 98e67ed59e1d1-2b6c70faab7mr32624976a91.10.1715950156637; Fri, 17 May 2024 05:49:16 -0700 (PDT) Received: from rigel (60-241-107-82.static.tpgi.com.au. [60.241.107.82]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b6710565e3sm15392349a91.11.2024.05.17.05.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 05:49:16 -0700 (PDT) Date: Fri, 17 May 2024 20:49:11 +0800 From: Kent Gibson To: Hagar Hemdan Cc: Norbert Manthey , Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] gpio: prevent potential speculation leaks in gpio_device_get_desc() Message-ID: <20240517124911.GA435070@rigel> References: <20240517101227.12118-1-hagarhem@amazon.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: <20240517101227.12118-1-hagarhem@amazon.com> On Fri, May 17, 2024 at 10:12:27AM +0000, Hagar Hemdan wrote: > Userspace may trigger a speculative read of an address outside the gpio > descriptor array. > Users can do that by calling gpio_ioctl() with an offset out of range. > Offset is copied from user and then used as an array index to get > the gpio descriptor without sanitization in gpio_device_get_desc(). > > This change ensures that the offset is sanitized by using > array_index_nospec() to mitigate any possibility of speculative > information leaks. > > This bug was discovered and resolved using Coverity Static Analysis > Security Testing (SAST) by Synopsys, Inc. > > Fixes: aad955842d1c ("gpiolib: cdev: support GPIO_V2_GET_LINEINFO_IOCTL and GPIO_V2_GET_LINEINFO_WATCH_IOCTL") I still don't think this Fixes commit is right, and that would impact where this gets backported to, but Bart can weigh in on that. Cheers, Kent. > Signed-off-by: Hagar Hemdan > --- > v3: update the commit mesg > --- > drivers/gpio/gpiolib.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index fa50db0c3605..b58e4fe78cec 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -201,7 +202,7 @@ gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) > if (hwnum >= gdev->ngpio) > return ERR_PTR(-EINVAL); > > - return &gdev->descs[hwnum]; > + return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)]; > } > EXPORT_SYMBOL_GPL(gpio_device_get_desc); > > -- > 2.40.1 >