Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1999230lqb; Mon, 27 May 2024 04:55:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYA7Hyk3ff+KrbKoPLqPe7xrU1GepR6dRGpUu/Zb2lL/j8NOGGaSYy7RNbWN8kCLcxwKkjNu3Us3PKBXhMtEfBEtvz73rWlV7vvl2kWA== X-Google-Smtp-Source: AGHT+IFSflukU+bayYkVNmiGQuyg3PIdN2Sx6LtWIrncQc042Ev1mEksVejGy5SSqXngNs+MR3oe X-Received: by 2002:a05:6214:328f:b0:6ad:82be:9bb4 with SMTP id 6a1803df08f44-6ad82be9e42mr26370016d6.49.1716810911125; Mon, 27 May 2024 04:55:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716810911; cv=pass; d=google.com; s=arc-20160816; b=nPWM/5JedtrEMLBHZpWQboreGemSLcUYCdDGXSqbf4IEtx0ckkw0kshkfYs72swuPF vmKAt6iekQySXoSd8dFTdkHMLH9Dhe1LBeZOiFqX5M1chS6dU5cv5E74x0nD+Ad+Ha7S WAO8h7yWX70vHaO/BOfnRBAi4Bc0ST+aBPIO7HWNMY4j+DDJmW4rToGE5kc5RqKrbNfk gKSJw+8+9JLZoAxgPe/DDrZhh+1rJ3ONYU/iHQpKFjuwkjEDBVDLGDBTuW01WfFCvQae lsGjGikGLLJDe9DhJPDBH+nw/bp+fvUmUf217b38bj4ZfB52JSoDviU0iOR2o6sbhAz8 GmxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4jYNZGuufvcnAd1nYnzFJWOOAgslXCStrEQYQHkxTy0=; fh=0XtL9QWuNuSNHlEzGqPvzr1cje9E2qttdzKzLl02hP0=; b=XefN4BNiw6iCDpmCwiAvbxJIGoFUvvuTt3mR5uDDfNzp3qevi5UveIxfxeHRUD7bzt 2v/Zhr+m3qYHTlmh6LVuZ8H0zAA9qAF6LFuxIJsw/b8VbNnzvIrmO+/SIvG1Q4NSGyk2 e5Ju/ABouIBhco3cEd/XaJkw2J3GfJPwK9IxBy20wMAWb2MRIDSGSJtypVxbS+3u//UH rE0Rye+hA9ri2X0PUt9mxAGPFPcIG+4mZlaGMII3OA3N0CYYFI+X8RsXKJnWE+nZjtFq 176gHFna4kWqLv5nROt9wHdBIZgkQ+jTqR2p1MD45/ST1n3uMOV4tXmLUcE19y27kbn0 TFLw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KG64d+DC; 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-190520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190520-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac162b38e5si77699566d6.496.2024.05.27.04.55.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KG64d+DC; 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-190520-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190520-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D90121C2085A for ; Mon, 27 May 2024 11:55:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 980C615E5D1; Mon, 27 May 2024 11:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KG64d+DC" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 8899313AA31; Mon, 27 May 2024 11:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716810884; cv=none; b=MR09q4QFHeXdQWtm5OQsaNMK/nwW+/sV6iIwRMGWqFFE2Ulfe7mp0gugBnhPLV2F96Qn7Ta2MxQIvhf6DZXgq++NpAqvf6J9heSBEIsJ8FPs0YAUMnxAwzrMDeJAndIyzbDg17Vqz+4pus5GiqJc9Y4OfqgIRBwSfpajRCpAD4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716810884; c=relaxed/simple; bh=UeKu1anSSx/heAnksOb9OY/e1ocsm3apk+xTukJJzeY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iqvQ6FDTUlqeXCXao/uVT02gg15eHsBycI0Pw/UJJz5D/Qc0s+OsswRYE7vzH+34VtZcFTCY+/4DE5y4+y4xopHlmv0laq/NmNInGShpN/+tO0DPScRyl3iJqPZC9qAizHAgeA2I4Z+DycsU32piPT6bbQ5FjmZVOeQ99PKwT0A= 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=KG64d+DC; arc=none smtp.client-ip=209.85.210.171 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-pf1-f171.google.com with SMTP id d2e1a72fcca58-6f8ec7e054dso1964658b3a.2; Mon, 27 May 2024 04:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716810883; x=1717415683; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4jYNZGuufvcnAd1nYnzFJWOOAgslXCStrEQYQHkxTy0=; b=KG64d+DCxca9U6AdJWl9146yeeIsvLTJnahgEQY2G04c3Y7QmZ8WDGEPqJOFylDS+S 9ucQYJJ8CMWutZeiqw0Ni1g6y3a0dDxoZ3n9hsPq+iIE7fDPZQKCcgA/u2axdqP6oXcJ neyVlDoHFfS5iVhqo+TPql5RgQaWaiP9E8TQeH24i74gxhyx9cujspLdS9vxvQOjO2fK cAUNIbygRzHsdOGCC3ctemlxfzRgEdwCpzcqnxzL9C2k7NAwgIHt8s5stI3rPa+HF182 0yWYtCqCWDJZVGw9lfkXu+Koe/cOlfoGsRHbH+6n0CBVt8C+IfbgjNjsifG6KHE8l1+8 H7Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716810883; x=1717415683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4jYNZGuufvcnAd1nYnzFJWOOAgslXCStrEQYQHkxTy0=; b=B59Zr1SVtP9jKlmRls+rO0/R9LPViqlV289VsyaaRo9hBnYGpYiF2hMBLGnf0zAm0M j9ShPVbx0KYtliDtHx248Ari11oNcH8F1g/UrEdjYlfznyKAdZKzQOyIHkbtPXsFagAq s3GiFZwgkwh9HS8DEE2HooZMEviWZV8hPlBnt4vxonkGzb+D6T9/CZQ6omolyHFHSFQP IhfIw7HSiHB8Q/b6GPgOfwLzLHWOjFWgNTJWHxNcDA0CY6X/XGKeP9AkDkwywCf6Wk7m D2C/ODz9c/IJ7gflJBAlOBlrdYDpq2ksKdKFpuRh/Gd99XSRE4nmSrfymLjOkhdRTcye 5tAg== X-Forwarded-Encrypted: i=1; AJvYcCVxLu3BlTSlXMj68ZxHX9TszKNGBcbX3O0dX344n/KOHzODBOX81qy7RxN+ROqHdPdc6k3Ea45TeNXvFfZbeCTh6BvtJsCIIGCvGA== X-Gm-Message-State: AOJu0Yz7jvnjNlFkObU6tMGVJHxUiyljF6r3ln12gcDu68VMxl8UYkFK aU4WIK8Xjkn7+Hgsnp1X38iP2BsVOhIM1kKdXeJXAUXYeQ5RPvIGDy52EA== X-Received: by 2002:a05:6a00:27a9:b0:6ed:d8d2:5040 with SMTP id d2e1a72fcca58-6f8f3b38a8emr13144173b3a.21.1716810882608; Mon, 27 May 2024 04:54:42 -0700 (PDT) Received: from rigel.home.arpa (60-241-107-82.static.tpgi.com.au. [60.241.107.82]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fcbea8a9sm4749256b3a.139.2024.05.27.04.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:54:42 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 1/3] gpiolib: cdev: Add INIT_KFIFO() for linereq events Date: Mon, 27 May 2024 19:54:17 +0800 Message-Id: <20240527115419.92606-2-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240527115419.92606-1-warthog618@gmail.com> References: <20240527115419.92606-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The initialisation of the linereq events kfifo relies on the struct being zeroed and a subsequent call to kfifo_alloc(). The call to kfifo_alloc() is deferred until edge detection is first enabled for the linereq. If the kfifo is inadvertently accessed before the call to kfifo_alloc(), as was the case in a recently discovered bug, it behaves as a FIFO of size 1 with an element size of 0, so writes and reads to the kfifo appear successful but copy no actual data. As a defensive measure, initialise the kfifo with INIT_KFIFO() when the events kfifo is constructed. This initialises the kfifo element size and zeroes its data pointer, so any inadvertant access prior to the kfifo_alloc() call will trigger an oops. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 9dad67ea2597..d4e47960cc98 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1774,6 +1774,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) mutex_init(&lr->config_mutex); init_waitqueue_head(&lr->wait); + INIT_KFIFO(lr->events); lr->event_buffer_size = ulr.event_buffer_size; if (lr->event_buffer_size == 0) lr->event_buffer_size = ulr.num_lines * 16; -- 2.39.2