Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp269342ybi; Mon, 15 Jul 2019 20:34:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwS6Muod8xUHNbXgK3d6TrcxIOClWVKEqhMtx+bJ1sBdU2lswF0RSb4+n0K0xxdMA50D9ha X-Received: by 2002:a17:90a:9604:: with SMTP id v4mr32584915pjo.66.1563248098731; Mon, 15 Jul 2019 20:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563248098; cv=none; d=google.com; s=arc-20160816; b=Lt91a8Q2PLjw9nhb2O41+1C7mmN7YNag/PqFGccj7aHxAgl1AUxyI+riaSUvQrbi2f cTm7K35Iqt0ScUBrARsNIjSq0zs00WUHQZPR6Bp46EBlkfQP0Y0NQ/jGE2EIdIBmWHbl j7Aacl7GSkByiiqMyYKwmujDX8u3922xhFEp+MEP++xZosNUUbuQfsm/zeBFw5Cxhx7l MRw8ej8UYAP32aaUajNz7BUeeZDXotAdGyovgS5j44HNYw0mBgp6PlKoxl+egtWbkwn3 NnJetOTVpZfdGWse0nuWjc3dYRBPIP0Z+9qjWMDBI+5f+rFsTspXfvDqlj4OZkECQYm5 RMkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=xC/c1W4LGyKMoN2FeMmzo9Wrzexm3+voeGFpDLnQsAA=; b=FatlaN4Kk8Bzd5iQXSpSV+AyKCjUPd4DRdUxLk8JZz1PyeQ7pbDjEzgRZMPqq67KMC 39ulnZwYs1W/lftgtz9AzY5+eLrO2WWms/lMGTzVjXVsk3qzVBdRqxdyMNiBIzocLJwt yBYxdAhLtsWBA1hbgthAK6SOyueW1kt5vDlmDdAMElj5WHWdYm8uMiXa9EtGdSXCFPH8 Xa6LJNXHN3yNMy9cUwSfz3hzsmINDZkjtKIdwWii5FynHh/u9gz4yD7eywyJJ79wGSNj qcSC40DZeRVurC4naVX6j/e2hsgMY9XUi5tDKcxJL3hNCDd8SKviIV82MIdyTyXXwqJL KXiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G+SG913I; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si16972127plk.388.2019.07.15.20.34.41; Mon, 15 Jul 2019 20:34:58 -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=@gmail.com header.s=20161025 header.b=G+SG913I; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730750AbfGPDdq (ORCPT + 99 others); Mon, 15 Jul 2019 23:33:46 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39917 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729574AbfGPDdq (ORCPT ); Mon, 15 Jul 2019 23:33:46 -0400 Received: by mail-pl1-f196.google.com with SMTP id b7so9351272pls.6 for ; Mon, 15 Jul 2019 20:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xC/c1W4LGyKMoN2FeMmzo9Wrzexm3+voeGFpDLnQsAA=; b=G+SG913ItNx85eheFC9l6D9a8JAJFEd9OAgJ+iMmqgxUuV8S7Pb1LUYFJAp7egAK+7 7VhAAwde+MzMaZvibd4/K+WcWAxijwQlm+YNOY44p8xwtlbmn3+iGIQeDlCrnAVqgRgY smNSBRcEg01w6o+8jxYbNW9jrWZu/sQ8CHoEe7Wvs38bFrnKezrDDiSCOvKNHbIE2wQE jkqVQwi0Luc6NRVHqH0AzQiUANsYzb2vcdwnl6GJA9o2dwv9o/1aND7dZpW5BoJM+Ndh GkWOLKBkzI8LscEwn77cNn5yCE+wfQcSEztvIC0Zxjqi3TvrBGINJg7xOBtekW/SkK0E agPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xC/c1W4LGyKMoN2FeMmzo9Wrzexm3+voeGFpDLnQsAA=; b=DNNhMJdEIr18cSldFMmdBWQzxgvayG1P07OtQzuhCSS8QxZ07i5qi7K4uNukGDKIc6 aGgt85zQtHY9LJejfS4SGYFSDa6YXgphKSsDUpfFms5esJdmExuWGheogJLYog3LjGKe 6Gj3nDI/IlZk49TTNhjJ1S7EYoZ/30wJtt7iIu9OJAFKPLqBt8zOu/5mweMz3TZ8lXoj shGZtUh47fKVN311Mu4UGucEMCgNNhTx1a3Aoo7J3NbqShNJ4MWkNIfu6ld8i656/JhJ wl/MXLPMXrkzusx6r3eLIclNm9LdYHPtD6E55ZsByVa/q2IdsovCY95CyzisISQRd8e0 TDBA== X-Gm-Message-State: APjAAAWuK7VTTMqeSuUitjPmAjxV8V/v+VlOv/7UpmXuSUSrXPvJnjlD 48UkorkkDX68aR3ivQn6tqRGR9rizo80Pw== X-Received: by 2002:a17:902:4501:: with SMTP id m1mr32570267pld.111.1563248025728; Mon, 15 Jul 2019 20:33:45 -0700 (PDT) Received: from ubuntu ([104.192.108.10]) by smtp.gmail.com with ESMTPSA id f12sm17311065pgo.85.2019.07.15.20.33.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 20:33:45 -0700 (PDT) Date: Mon, 15 Jul 2019 20:33:42 -0700 From: JingYi Hou To: mingo@redhat.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] sched/core: fix double fetch in sched_copy_attr() Message-ID: <20190716033342.GA32294@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In sched_copy_attr(), attr->size was fetched twice in get_user() and copy_from_user(). If change it between two fetches may cause security problems or unexpected behaivor. We can apply the same pattern used in perf_copy_attr(). That is, use value fetched first time to overwrite it after second fetch. Signed-off-by: JingYi Hou --- kernel/sched/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2b037f195473..60088b907ef4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4945,6 +4945,8 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a ret = copy_from_user(attr, uattr, size); if (ret) return -EFAULT; + + attr->size = size; if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) && size < SCHED_ATTR_SIZE_VER1) -- 2.20.1