Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp841897ybi; Fri, 12 Jul 2019 05:33:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzttrBlxZduhrqB1hiJhi1Kihq3Ht/P+IPsxgDAYpmao66oFvDJ1QeSfPln2sWPe00B73Cq X-Received: by 2002:a17:902:7781:: with SMTP id o1mr11249452pll.205.1562934791202; Fri, 12 Jul 2019 05:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934791; cv=none; d=google.com; s=arc-20160816; b=vJEGqy00prJTTqHLftO5VoFTozYm0F7N2xS5She70dBwLrBvq6S3IXcfaOWJH9XjN6 FCbQ3O0lRagoE6NbPxFE1UC+vjs0jHWnkA+mlKYFg10ynxnnRmu71ilEACIdRdcY03Ye Un6rHxz5QmrikZG606Yeyj4jR6zC/k6S5JHym4NPqqhR5ZT3JMEGvad9bN5gGHKaRol9 MXb3UBOUYHTDPf0maMJfYYzPq2IAhBLcNFHxpH/SIEL9Yr/whiY01Jobkj1nXEOWUhKc urlLeeV6CTUppJOXBYt5dW8wsLBegGwKimiU8F/FGmYYvA9oLudWiFYGSOD5xvcPM6yw E/qA== 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:dkim-signature; bh=TPjmL9xs7LwMVrTbWiO643jxJGo3Q7QjZS18LNHFu6Q=; b=xc6hNa2FArzpkBdZv/veTfpRldJ5FET2f1Hb5tgmaYAgS5eZvGOrH1daIDxHgs182+ +QPhgH0lTG71UP60gXHHo3JzWgDtqcdQq5tR9k20bHwDHwcyZqqCQWWntj+QD+3mZym3 7qS86U7JegU5it1CEAOhFTjQkc4kEHtW1UGXQ+eNKOXaCejpvx5J77K8JTLy8dnUlfeM 9o553rBRqhzdF4QIiKJU9UyvLHbz+qOqDKSlSTzhB+LCDFw6jYmTVYLum9TNXOyc2CQL i/rOV529mN/Plm8PzmoIOcQvhqLXD2DwgaQ/qd+vkHYyNLeZMLtxCApdG6hV0zhP6lEJ g/5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Auc6L5vT; 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 q4si8331391pfg.286.2019.07.12.05.32.56; Fri, 12 Jul 2019 05:33:11 -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=@kernel.org header.s=default header.b=Auc6L5vT; 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 S1729232AbfGLMar (ORCPT + 99 others); Fri, 12 Jul 2019 08:30:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:46748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbfGLMan (ORCPT ); Fri, 12 Jul 2019 08:30:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 30B7B21019; Fri, 12 Jul 2019 12:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934642; bh=SU4PiBYQHblcoQfdfXgyW6tkP0XAavHdR37x6kfL5Vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Auc6L5vTPDAxQFp8nZXhSIUQSSXkqw0Y9CZMrQJ6crTjmMSExeI3Q33wbBdCIS29+ Rkt0G7GWct5sjoJok20iLakORTg57nuwphn8iXJsDDMG02r8P3DavUPuS4q+TT17d7 7m5FcxbrDAmxyAq0GCwXCroLVDOaeNFqrNJXI+PU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Sean Paul , Sasha Levin Subject: [PATCH 5.1 079/138] drm: return -EFAULT if copy_to_user() fails Date: Fri, 12 Jul 2019 14:19:03 +0200 Message-Id: <20190712121631.751652291@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 74b67efa8d7b4f90137f0ab9a80dd319da050350 ] 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 Signed-off-by: Sean Paul Link: https://patchwork.freedesktop.org/patch/msgid/20190618131843.GA29463@mwanda Signed-off-by: Sasha Levin --- 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 e407adb033e7..4fbc34425570 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -1332,7 +1332,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 0e3043e08c69..f8672238d444 100644 --- a/drivers/gpu/drm/drm_ioc32.c +++ b/drivers/gpu/drm/drm_ioc32.c @@ -372,7 +372,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