Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2467244pxb; Mon, 19 Apr 2021 06:28:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziN3E0exYgTlxG74kGlxic/LW1J6+e9c0wvc9Gz9tkHW3AxlMTe9ANdQ+otMae/crM84jb X-Received: by 2002:a17:906:d8cb:: with SMTP id re11mr21525410ejb.204.1618838934786; Mon, 19 Apr 2021 06:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618838934; cv=none; d=google.com; s=arc-20160816; b=z9XKpK1dolNElkg0AVTzp/Tv6MeY2sC7Zsdkot3OktcB7uawp5+MpUhgsDaVJIWpTz +TQMFI2NIlz9M52whoSErqx6zHSEJNy3/j6CwrZRNt+rjJp44fMlP95jecj4ads035jE G93Craphc9JMk2duntlmaU/pla7XpSNiNYgPz9mCA/AzZcPOhql4jax1jPqp4KLZK4XS aO9FEWG3gv2tn9iAV2eKgUPfjy1CNoPtTaNbOumZG1GNcEjp115QOI555YNPvSzH6p4L ghlcQ60dNjc+bT27GoTMuTTam213eDjJ2fsbPvpUtfH5aNL4kjbIo6RBfsvXgXPZlu8y Wg6Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MwDjBB2Hm0PnMwZNBdGlSXcFbEqJkI6BERiyEoC30kA=; b=V6I7M0GFgaqKztwpHhdPftNhSMKl+PnlONcz0r90fzPB+0ygp2S80+hCxz7WS+CzFh bQ/1A/s/k05uKelhTY18h100gkPpWWWi73MUsfPZQxXqBVRzY2CnlFziwsI1R50bqFhc HQj62zocyACIwrs5Ak2qBbyZzZxWTyn7lCpCYzj/5W4bKTEuC/nxWutXMOv3EupNcCA9 FODxRrhXyvcCEDGR2oX3Olpymi9Z2+B7RHzMpnoDVici0uJwdpitVI+EGrzcwJufCxbH p6/Zl1adrsSQddape8GtkRf+auF8hdouotNmyg9u1JPxZwaMnmYoULThI+jNYj++Zgv1 5bAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MTtSlNzl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si12114258edr.450.2021.04.19.06.28.27; Mon, 19 Apr 2021 06:28:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MTtSlNzl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240784AbhDSNX5 (ORCPT + 99 others); Mon, 19 Apr 2021 09:23:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:57240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240810AbhDSNSd (ORCPT ); Mon, 19 Apr 2021 09:18:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80A48613EC; Mon, 19 Apr 2021 13:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838091; bh=I8dRn/9AxOCx/sjYCzLNEaia4bgiL2+/oOCTYbJWbdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MTtSlNzlms3st513jK2vEs1uaMRBHJg6aUntO70HKggduE7BJB0WFppuE8agYUkel ny8r93im4QTIa6z25O4stfx9E885p3IABEGoL/jsBQxI4Ivpgd7gH/xkiofaGIYNfA fAKnlYiO/mOopZYw0AbMPsMwKbxZA8ndNiCxbxao= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matti Vaittinen , Andy Shevchenko , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.10 004/103] gpio: sysfs: Obey valid_mask Date: Mon, 19 Apr 2021 15:05:15 +0200 Message-Id: <20210419130527.933470612@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matti Vaittinen [ Upstream commit 23cf00ddd2e1aacf1873e43f5e0c519c120daf7a ] Do not allow exporting GPIOs which are set invalid by the driver's valid mask. Fixes: 726cb3ba4969 ("gpiolib: Support 'gpio-reserved-ranges' property") Signed-off-by: Matti Vaittinen Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib-sysfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 728f6c687182..fa5d945b2f28 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -458,6 +458,8 @@ static ssize_t export_store(struct class *class, long gpio; struct gpio_desc *desc; int status; + struct gpio_chip *gc; + int offset; status = kstrtol(buf, 0, &gpio); if (status < 0) @@ -469,6 +471,12 @@ static ssize_t export_store(struct class *class, pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); return -EINVAL; } + gc = desc->gdev->chip; + offset = gpio_chip_hwgpio(desc); + if (!gpiochip_line_is_valid(gc, offset)) { + pr_warn("%s: GPIO %ld masked\n", __func__, gpio); + return -EINVAL; + } /* No extra locking here; FLAG_SYSFS just signifies that the * request and export were done by on behalf of userspace, so -- 2.30.2