Message ID | 20221201083335.819190-1-brgl@bgdev.pl |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp145768wrr; Thu, 1 Dec 2022 00:42:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HXTaQkzJGo8fs2lhHXAnZpkDq8xt3mN+2lG11iczZ3yzg6cN33/j6b32WjYLjrbPA9uxw X-Received: by 2002:a17:902:f812:b0:189:9a71:109b with SMTP id ix18-20020a170902f81200b001899a71109bmr13178563plb.171.1669884154529; Thu, 01 Dec 2022 00:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669884154; cv=none; d=google.com; s=arc-20160816; b=Nfs13imREmrigup9TXSZjWGMMu/0W9+PnwSN8A9ui322wYcIjahfdHOJi5mF57uZ8+ NwkPzlKurQn+E4Bx+PbcoDd6DldPFSGJmdvwPaNOxMCHV1SlGjYhDzI9XwtjNjVXBobo 42NAfDCevqzQ5Hik00ysW+o6XPfATRaKuO7glwNSrvo1qX7VQkjSAva82a20vGrIX3JG lKL8Lf885fzGMCn1rM+qjy6WZcsBswLew4sQi2iegwlcrsIEW7vwHYEoxG+j9/jtg3Fo XWp22g5aUkPLFHw/9pOZNf3H9c2TAWBT1AoHdwYqwnatwQVXXDQC6VUQ48+pcMVtpXh5 xY6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wX0uGx/FmFRDa4kSdWRlloB+K4Vw99mHzIFHONaLerg=; b=WUMr6EeMfRiofsKxjkmH62FKrHe3OaWCE7F/B+78H7zT9nK8wMF8J0vX9ccwhx2/5G Un9XFK95R0f3QppfX60hdUruX6C8VpUWjGCRSb+5nsrVBE3lizjs2/+Ur3I8Al+Rk4Ci gccvo1BTtJWb14BjIzvM+elIF0NOVEmflulnjTgi5abS+0aRagBafK8+Eq5GBsdsbRS0 V//G57ex4NJhOdhhkLZtXFJX16EgHcWpotlNkh+p23E8nyVaQG7Eu0RovtqPzXGBBIzt cgTTmw63+XiDkUK3lUNF+l5fNKlYtVGOXdEd6A4WSLJ769juZ8ztMk+FB3if6Iu4Xg9t PndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=InQBr7oL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a170902d51200b00186f81a0765si3979063plg.540.2022.12.01.00.42.18; Thu, 01 Dec 2022 00:42:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=InQBr7oL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbiLAIdo (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Thu, 1 Dec 2022 03:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiLAIdl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 1 Dec 2022 03:33:41 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3504C241 for <linux-kernel@vger.kernel.org>; Thu, 1 Dec 2022 00:33:40 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id m19so617928wms.5 for <linux-kernel@vger.kernel.org>; Thu, 01 Dec 2022 00:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wX0uGx/FmFRDa4kSdWRlloB+K4Vw99mHzIFHONaLerg=; b=InQBr7oL475ZoNWQv9JfdWq7nk0FrTxkDD9rlFhPNZxxYYFD3+FXZhFJ/ls/fCj09t H6Rox6mplA/LjjmwPtLmM8SvQ+qXVE/xV14LuHakEaI8pbGyvlLe30VsQ/T6cKzpUnOd Qi2B6JeAf09dPr4zjljGnT2H+ouQPMCQOLf5lsdRyCiigYhfNuxJGnFApAcDVCV1vYHo O4JofyO1rNDPmVOu0NcC3+dcxaqCKGcKzbA5kYxTUNg+eOO6mfljYYT5F/13/guDMQID XwLRkadG7haQRwyzAnW0Nr7sQ9Ov/79BvjKqs9/8vwnAyCfgPYji9MAAHjQg81L43BnY 2fzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wX0uGx/FmFRDa4kSdWRlloB+K4Vw99mHzIFHONaLerg=; b=4AKCNNRVh/3sPDm1Ve/HnamEj01snI2Qul3E/ophGAEdDy+YC6nSk+nBbJQxxhpLSu ClqkNH2B4aNgc9YMDYs3UqPruqSeGb4t9gmMYfaqLXo0PYTW7HJjtcrBJ70Wb1kM9rQc GzRZfIT87l6wx12WMoqJyBrdUzkVmEZIG4nG45E7Qle3IppQUuLjtcsjQttLCv6uuDTJ vz+txVR+/9+OTXPs5qy8aEvvAYC34vDiUe7gGzsf6lnNN83S8drdnfcHAPHoZ9+C7Ji9 d7s8600EHfiRhsDkk2UkD1vqg2xRr7JbtVSTnPervu68OE6Su1rU2X0tA7RYgMHKSHAB oEpg== X-Gm-Message-State: ANoB5pmc5fMJWUx6AJgTn/izY55e9ivw4QYpSwTqQwSWqzqi5c2zAUfn My8Nov5PrB7hSH8GSG9Y0z9rdA== X-Received: by 2002:a05:600c:5118:b0:3d0:7026:49eb with SMTP id o24-20020a05600c511800b003d0702649ebmr5618756wms.53.1669883618685; Thu, 01 Dec 2022 00:33:38 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:26bb:b860:c227:f05d]) by smtp.gmail.com with ESMTPSA id p15-20020a05600c358f00b003c6b874a0dfsm6132349wmq.14.2022.12.01.00.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 00:33:38 -0800 (PST) From: Bartosz Golaszewski <brgl@bgdev.pl> To: Kent Gibson <warthog618@gmail.com>, Linus Walleij <linus.walleij@linaro.org>, Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Subject: [PATCH v5 0/2] gpiolib: don't allow user-space to crash the kernel with hot-unplugs Date: Thu, 1 Dec 2022 09:33:33 +0100 Message-Id: <20221201083335.819190-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751000447246318591?= X-GMAIL-MSGID: =?utf-8?q?1751000447246318591?= |
Series |
gpiolib: don't allow user-space to crash the kernel with hot-unplugs
|
|
Message
Bartosz Golaszewski
Dec. 1, 2022, 8:33 a.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This is (hopefully) the final iteration of the changes that aim at fixing
the situation in which the user-space can provoke a NULL-pointer derefence
in the kernel when a GPIO device that's in use by user-space is removed.
v4 -> v5:
- try to acquire the semaphore for reading and bail out of syscall callbacks
immediately in case of lock contention
v3 -> v4:
- use function typedefs to make code cleaner
- add a blank line after down_write()
v2 -> v3:
- drop the helper variable in patch 1/2 as we won't be using it in 2/2
- refactor patch 2/2 to use locking wrappers around the syscall callbacks
v1 -> v2:
- add missing gdev->chip checks in patch 1/2
- add a second patch that protects the structures that can be accessed
by user-space calls against concurrent removal
Bartosz Golaszewski (2):
gpiolib: cdev: fix NULL-pointer dereferences
gpiolib: protect the GPIO device against being dropped while in use by
user-space
drivers/gpio/gpiolib-cdev.c | 193 ++++++++++++++++++++++++++++++++----
drivers/gpio/gpiolib.c | 4 +
drivers/gpio/gpiolib.h | 5 +
3 files changed, 180 insertions(+), 22 deletions(-)