Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3774145ybi; Tue, 18 Jun 2019 06:21:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4pqoenp3/oVq5keuidg/dBFAWybW77JpBMTCQzRAQLS+FK5e3NArc/MGYzn+mEDpEcBIx X-Received: by 2002:a65:4347:: with SMTP id k7mr2750053pgq.253.1560864116232; Tue, 18 Jun 2019 06:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560864116; cv=none; d=google.com; s=arc-20160816; b=ZZ7Ez7HzkiawT8UUWIH7NY+LmbJUwlRFhQGPFugSgJzTyEoa5BWpyJEJ0ltdR4tdiW t/P7CWo7BsRo3QL4ogMjllIKuu8H0GiTvRkDCLjddBmfvIkrz7MsE3kHktlnI7gRTfZq tjP5XPVJ47YmhUnVv8+Hkuf7t1xhPJ4kfF/eT24dcfbPQt53dwOK/HNkUJPL+X7dQISh h5/fHx3frYx0FHvDQ/TR2uFfDqFKCE+eh1EsrTQmS7PG/tz5LXCDosy6ibF19g/np9rr d0JCpGwSRpTyaISLMlOeaD5QOTclPsQcoAKDZ1oYgFOfRfm+bm5iOil6LyR76qqAjnmK mq4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=6YGkq/bCxydXzjE3rIrKm6a3Acfpx+eRiztMObFEoXg=; b=ZCUCPWmDb7RPe0Erq0ur8axbQpKIYUM0Ba0UrezbjkmiAhQqCp4t+2IwK5w3QiL6+w d0z32nvcJ4qahG0Ate0COrr7znLoaZND/3R52eoofTYKbkFZYRQj2tyzBvBBkAmLWtzY d4gP4zAY8VZW+OslbWEPaO/EvMWosbztPotZfKCYA0OaSnMfjumqD2xYB+bwB7dOK49A uouKUEfxaaZ9yxD2Qvacl+yzFhYDQYLV47ypfcd06yWeEEedmkuA/3Ms9v3wrrYkUu0a 45rBJ4c548vvi0PHofI/Q+uZzPHcs5Ii6OIup9AN20jbLMjS7oLDoe0+EZuvGplVYUMS S0Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=szGxjT+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si184362pgs.457.2019.06.18.06.21.39; Tue, 18 Jun 2019 06:21:56 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=szGxjT+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729079AbfFRNUK (ORCPT + 99 others); Tue, 18 Jun 2019 09:20:10 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:58008 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbfFRNUK (ORCPT ); Tue, 18 Jun 2019 09:20:10 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5IDE9H1141039; Tue, 18 Jun 2019 13:18:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=6YGkq/bCxydXzjE3rIrKm6a3Acfpx+eRiztMObFEoXg=; b=szGxjT+WzGnmVTHS6PTQ63MPSBOaFfXc5TyDAhbtbG0bTU9QX6VcGaveSH+d/fV4cXyi u0jVZXOGh9X1OKvk/KMFOjOgV0s9bCg3gwzHeo2l0GrZ9co94BVo8mNri+25Y0h+S3OO ly+KilgEjDo6dQU6swmenO8Hsu1kQiOfbZHvF/Um43HMIuZB/dKDJx6o0+PhlSOpnV3S kJ/IVhacdQAUX/3XSZyUYlO+izAOGADcJK1q4Mbn0Df0Pl0NhBZWAkLbAvI/1uuKWmKN sZA1MIhUY6pdWbS37zPm8QtCIXxx8H1tQlnxDtj0mMpqCEjwIA2+CrDngTXKv8Z2/CIa tw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2t4rmp4e27-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Jun 2019 13:18:57 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5IDHB6s090801; Tue, 18 Jun 2019 13:18:56 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2t5cpe1u9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Jun 2019 13:18:56 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x5IDIqdR004779; Tue, 18 Jun 2019 13:18:53 GMT Received: from mwanda (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 18 Jun 2019 06:18:52 -0700 Date: Tue, 18 Jun 2019 16:18:43 +0300 From: Dan Carpenter To: Al Viro Cc: Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] drm: return -EFAULT if copy_to_user() fails Message-ID: <20190618131843.GA29463@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190618125623.GA24896@mwanda> X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.10.1 (2018-07-13) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9291 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906180109 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9291 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906180109 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The copy_from_user() function returns the number of bytes remaining to be copied but we want to return a negative error code. Otherwise the callers treat it as a successful copy. Signed-off-by: Dan Carpenter --- v2: The first version was missing a chunk drivers/gpu/drm/drm_bufs.c | 5 ++++- drivers/gpu/drm/drm_ioc32.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c index 68dacf8422c6..8ce9d73fab4f 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -1351,7 +1351,10 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from) .size = from->buf_size, .low_mark = from->low_mark, .high_mark = from->high_mark}; - return copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)); + + if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags))) + return -EFAULT; + return 0; } int drm_legacy_infobufs(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c index 586aa28024c5..a16b6dc2fa47 100644 --- a/drivers/gpu/drm/drm_ioc32.c +++ b/drivers/gpu/drm/drm_ioc32.c @@ -378,7 +378,10 @@ static int copy_one_buf32(void *data, int count, struct drm_buf_entry *from) .size = from->buf_size, .low_mark = from->low_mark, .high_mark = from->high_mark}; - return copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags)); + + if (copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags))) + return -EFAULT; + return 0; } static int drm_legacy_infobufs32(struct drm_device *dev, void *data, -- 2.20.1