Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp835329ybi; Fri, 12 Jul 2019 05:26:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvlP72iJXp+ebGkNlcOQ6ULNj/gfKKHcewPRhcy0Rv+r4D+y+mo13lHu/BFtM8r356yOP6 X-Received: by 2002:a17:90a:1ae1:: with SMTP id p88mr11057039pjp.26.1562934411040; Fri, 12 Jul 2019 05:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934411; cv=none; d=google.com; s=arc-20160816; b=nSivPAtWTumlTrEMMbDTtYfM6ro234Mnf/ySwYMGNtqNKVmNtSIoBqHifIFHQ2ypuv MHNwhKtjpKKmY/enRNTg8KvFJli7Fysdx7auL+FQ2DU6X8E6HpRRF7lVoSAGdlHpMCVR yXkoJpxSYtvDMtUc/k+IOCDdw52yRhgIiFcJ+aG2L/g4++jB0BCbfnyqjzOBDDhmy4rX kgePYjCZrUjfCFnYC3xbEZCFY3VoMW8aeabuiJoc9nq1UZpA7a1gytPv2oCiMhuiLnHx 5MBCMDUE5CkxPIsBw1fSSvBR9b2uDIR++GfSI71XKqyrEbxix8G4qWyJiUbWXOgH/cUA gNeA== 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=mEYTNSrH/TGfBnRoCXjE5qx3snpxN9SGVEyH4F4neic=; b=Mw+iGpgNFKtMM4wIZrq/qvEpTUwzgXSE50rF2nm9DRfQpho5zBNToZn+T2X4OiOmuz Qx4/XEtv1T80w9Q2sCP/ATg90Get/5Af+26JY5PvoQ9C72nd4jkjN63K76NH2DWBe5gw BBYh/h/bbl6JXOixqJF6tAuMDBjGgNipvP5syX2cmuv5WHjJVGzYGKpgCZduU2+1I97f gFoHGreZuQyoxVf0CZ5VD97vUfZUuDZPYRpXKTfDtB0xMfkn+eF/IkGxJvY1Im9PzFcX U0sMW/0XoO4WnVUP2tBG8k6+kButtP//Mq8qcN2LM4OHGuZ0UDB+96LQrjGedDO/lUu9 gEkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u9RwUGNS; 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 j63si7700417pgc.185.2019.07.12.05.26.35; Fri, 12 Jul 2019 05:26:51 -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=u9RwUGNS; 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 S1728083AbfGLMYU (ORCPT + 99 others); Fri, 12 Jul 2019 08:24:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:60596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbfGLMYJ (ORCPT ); Fri, 12 Jul 2019 08:24:09 -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 A632B2084B; Fri, 12 Jul 2019 12:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934249; bh=RYgNIcgVq4MvcSezTMgFH6yH/BO/iiWP7tZ6Y9Kxu5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u9RwUGNSBHgYu7MG6pZZ2FoUiP9bqd8zS94OFamcj8lh3D0bzPTeVbiAVpMq/tbcL i9qi5pz87BbFsOeWFP58AowlwdqrlDNuOiupUybBvalm/z3JEoDE8W+4mBQ2j1/6d0 OYwbJVqnMAkQMwU4BvhQ2VR3V9dk64yEn/EztOnM= 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 4.19 48/91] drm: return -EFAULT if copy_to_user() fails Date: Fri, 12 Jul 2019 14:18:51 +0200 Message-Id: <20190712121624.199415799@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121621.422224300@linuxfoundation.org> References: <20190712121621.422224300@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 e2f775d1c112..21bec4548092 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -1321,7 +1321,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 67b1fca39aa6..138680b37c70 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