Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2511522imm; Mon, 24 Sep 2018 05:42:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV63zqOYK4+GSUneUMa/T4Y9hzmXhSrinh3WOrKt0lwpzNPbFgZMLQ/+kMZTPv/7tXGHxN4bE X-Received: by 2002:a17:902:585:: with SMTP id f5-v6mr10652742plf.7.1537792965489; Mon, 24 Sep 2018 05:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792965; cv=none; d=google.com; s=arc-20160816; b=bk/+MJAgB1uqVkoTTBM8i9kxKohJnkx2vOJPXmy86RTWVXUs7dGSG+nXg8nmjCFwlP n9b6xNDr95cmBgXdr2gn6FaO66jVNBifi/0Kqd+h7TwG46rk92Q5vAD+l8v7TOThxhI/ BCi0NQFGXAb1OIPy/SCtzVAeYST5S2jK0Ls9AZtoWbz/ucHnvwm2D3noY6WRIYISWKQg 720etAveA8ONUgkeG0ZlrAaMINb2gQ6xb8euUiqljYcOuETcBr4LeZQOJtC2Bf4B+WQS n2FUMaL62Br/gdftTmurZeBLWcsEDhl8kXvV5pquR/ScKC+psuCmvD1Xxm3HyjWjxyF2 cZfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=gWQ5hA5ZAd2TtDRrgNWn5xOGs8bQAf27O1gTk/Tlngw=; b=P4C/Nzzc5LngjCos+wBJBxju/YsUTe3aUHMiet8Q8iFt7N0GAbZ+qSCWzpyznQhjV0 th8y+W6dOj8X+P40ADtje0eYKoWstxZRW8JRe6D8w1x+RT8vtfYCpWHr9TIB7I2Fse+4 qB+uxZo9MuHYhwARJiTduIX77QajDfArl5Cj1i0W+GSPQte8MexT5glFsQV/NqIzej2c rrgKbFVEu8HZuXzmCjGTrwoyeLmXmAKNX1tYucLp6iOXwqOuefryZQBacX+9BJ2ArnZg k+8UInE9wZSBzc/W89apfNbtJzyLyzyitnkQ7SRywZBPXlYeYeBcV0M3IICKnsMTEURG arbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14-v6si32680574pgj.685.2018.09.24.05.42.30; Mon, 24 Sep 2018 05:42:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388791AbeIXSna (ORCPT + 99 others); Mon, 24 Sep 2018 14:43:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59150 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729543AbeIXSna (ORCPT ); Mon, 24 Sep 2018 14:43:30 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 848FF109F; Mon, 24 Sep 2018 12:41:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartosz Golaszewski , Linus Walleij , Sasha Levin Subject: [PATCH 4.18 177/235] gpiolib: dont allow userspace to set values of input lines Date: Mon, 24 Sep 2018 13:52:43 +0200 Message-Id: <20180924113122.447077803@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bartosz Golaszewski [ Upstream commit e5332d5437764f775cf4e3b8ca3bf592af063a02 ] User space can currently both read and set values of input lines using the character device. This was not allowed by the old sysfs interface nor is it a correct behavior. Check the first descriptor in the set for the OUT flag when asked to set values and return -EPERM if the line is input. Signed-off-by: Bartosz Golaszewski Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -449,7 +449,13 @@ static long linehandle_ioctl(struct file return 0; } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { - /* TODO: check if descriptors are really output */ + /* + * All line descriptors were created at once with the same + * flags so just check if the first one is really output. + */ + if (!test_bit(FLAG_IS_OUT, &lh->descs[0]->flags)) + return -EPERM; + if (copy_from_user(&ghd, ip, sizeof(ghd))) return -EFAULT;