From patchwork Sun Sep 12 18:57:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kulikov Vasiliy X-Patchwork-Id: 173492 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8CIx4tC032715 for ; Sun, 12 Sep 2010 18:59:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753003Ab0ILS5K (ORCPT ); Sun, 12 Sep 2010 14:57:10 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:52144 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752072Ab0ILS5I (ORCPT ); Sun, 12 Sep 2010 14:57:08 -0400 Received: by mail-ey0-f174.google.com with SMTP id 6so2451339eyb.19 for ; Sun, 12 Sep 2010 11:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=q8oZeBQiPbsk8411lPfIArlbThXhznuw4y6gwWtaYSQ=; b=rMdKMoYesWSt7RE2THcz+45Hu8sKSzBfYa+78kqVdZAhuHmGhkkE9yPe8NEpGnTrQP z5P3I+3GZFVOwh5EtB09bB4kyYcq0rHo+/2f+wS+IygTEsZ+j8aia+CVtJDfSacFpNwO e+sbdH/MK1Mcs+a47nq9pSCIP7PXDddwjmATI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=uw/m3pC7Hk3zeYuSJTbPhj35BijGj1tSG4nmJ7lMaX+1f3qhk1OaqmiPMXTezdNM4d q4/ZDeTuNQ9IBnSMQr1UBY3eeWh56tMKMxYgf7Dy47KtJB9u2Ajyo/JBmnOF1osMRjOp 7kpkkTNSfIrzBOTBYKhhJTvwFflFOPVSzToT0= Received: by 10.213.35.72 with SMTP id o8mr2131615ebd.80.1284317827733; Sun, 12 Sep 2010 11:57:07 -0700 (PDT) Received: from localhost (ppp85-140-161-57.pppoe.mtu-net.ru [85.140.161.57]) by mx.google.com with ESMTPS id v8sm7862955eeh.8.2010.09.12.11.57.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 12 Sep 2010 11:57:07 -0700 (PDT) From: Vasiliy Kulikov To: kernel-janitors@vger.kernel.org Cc: Len Brown , Thomas Renninger , Matthew Garrett , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] acpi: ec_sys: access user space with get_user()/put_user() Date: Sun, 12 Sep 2010 22:57:03 +0400 Message-Id: <1284317825-4980-1-git-send-email-segooon@gmail.com> X-Mailer: git-send-email 1.7.0.4 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 12 Sep 2010 18:59:04 +0000 (UTC) diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 0e869b3..cc007d8 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "internal.h" MODULE_AUTHOR("Thomas Renninger "); @@ -43,7 +44,6 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; */ unsigned int size = EC_SPACE_SIZE; - u8 *data = (u8 *) buf; loff_t init_off = *off; int err = 0; @@ -56,9 +56,15 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, size = count; while (size) { - err = ec_read(*off, &data[*off - init_off]); + u8 byte_read; + err = ec_read(*off, &byte_read); if (err) return err; + if (put_user(byte_read, buf + *off - init_off)) { + if (*off - init_off) + return *off - init_off; /* partial read */ + return -EFAULT; + } *off += 1; size--; } @@ -74,7 +80,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, unsigned int size = count; loff_t init_off = *off; - u8 *data = (u8 *) buf; int err = 0; if (*off >= EC_SPACE_SIZE) @@ -85,7 +90,12 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, } while (size) { - u8 byte_write = data[*off - init_off]; + u8 byte_write; + if (get_user(byte_write, buf + *off - init_off)) { + if (*off - init_off) + return *off - init_off; /* partial write */ + return -EFAULT; + } err = ec_write(*off, byte_write); if (err) return err;