Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4745971yba; Wed, 8 May 2019 01:58:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxieG3Los73dMZbgIwyIJ8KwVVQqHuynvY5sDWbZweRpjSxy8HeaokZBbP/f4wcQKJ4tdkW X-Received: by 2002:aa7:8554:: with SMTP id y20mr29066344pfn.258.1557305885262; Wed, 08 May 2019 01:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557305885; cv=none; d=google.com; s=arc-20160816; b=zdB0Pn63S+A1UhIo4n3Er5QjqZmyp18Y9iFueTIR6VNSfynqP37T1iN22nn/DR0Jwf b4PpVFW9Un6Itj6uTikUDctP+jSJ9rd/7UYHYcxl6GPIcRZHkHg3hW5xQxahajeYAMmi 5lLAeqgT4rN5fgRtOya3pbD6zdRdHw8NoOPzRRh5s9+VWjnRBNe1b+erJnJBrMvo8e3+ 5QGPxaEjVc2qxAnEbr1K6DcFJ1yonN07PvVCaNVuy8fYMw/n4JC537XCynSRVDZV3j9+ 4CQ1ZxGyRXFlGEk+Z+JroUzbzd67yDk43op6Gfxl/Kfh+VOoaDKW3qBdk7kgL0w/kb5/ /7OA== 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=RzkERkWpjm0WKlrnqjyOqPq649NuvXA8Dfzb8RC5Ut4=; b=iH9e8zcFGy36g5lht1LEG3b4HD0hN5WRvQZyzuGnEyuFLVGHT3uJpuRJz6D25VWlwa OViFbdcTLtSAK32GPomauSQYhkf1gybZ5GOGncnWjUV6fi8buUo/tu+ZiQ3PwJgeSvug weBV8v1uoNPAhCGiB5ZtbMx4UrXOhgMMb9YcoJJuzSCn98+0bacLokDaWDBabMer20bt Y/qlBFkibYQMb9zupFLqYdW2kFn1Cwgau9Drq4lzrh/2Oi8QIxGshV5uGwvPBAqA1QFy YlY9zJRWmJif2pzlKp+bYLuasR0Rp3835Gn/EoanxQqH8f9EZ2OqwDrkY1YKpqD96JL7 h1Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AirRevee; 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 b8si22296559pls.337.2019.05.08.01.57.49; Wed, 08 May 2019 01:58:05 -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=AirRevee; 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 S1726789AbfEHIX1 (ORCPT + 99 others); Wed, 8 May 2019 04:23:27 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42578 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725842AbfEHIX0 (ORCPT ); Wed, 8 May 2019 04:23:26 -0400 Received: by mail-pg1-f194.google.com with SMTP id p6so9708181pgh.9; Wed, 08 May 2019 01:23:26 -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=RzkERkWpjm0WKlrnqjyOqPq649NuvXA8Dfzb8RC5Ut4=; b=AirRevee5YLPTty2QNwEMQ+LJU42DuxFAM9DtEhlJHEDgyTILTdoM5/gbXnIrF/7I/ ofgjP8bI026t7K+vE9WpPfMb51DdEvJc1REHZuX0svIwVzlyBw+zHlkYbcMX1rHItTtJ sI2gEbgLOZNJhyxYVLMC7bPs6G4ye0Hfwxwx6Apw/JkDahtqoqda5Vcczza9y7yu94cg 0FB5lkVXy5yirqxf+0lXli4MyQA8dWIQ776plqbriPXZsHiNDJnHwBsnh1AG29fhenQT FAfBU+1NTTAOCZlyWv5MYxuz4lnQ08nk7X8a8tQAnnIRUrlcSqqVkPN3Yp8rkBJ1doFl m3Bg== 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=RzkERkWpjm0WKlrnqjyOqPq649NuvXA8Dfzb8RC5Ut4=; b=quV33lxvlpZuGEN1S4SyrkCJmAYFOA0ry6iwEnltVXzp6Y6/JixzUvoeu5maIkhqmD dN41Mqnlna684F1KWoON5FjUzE9TT56+nnskBEgStHDi0n1q6uPAQ1gLDcFemPcdueMG zTSi/SSxFrYi4jVgja7ZtRwec5lNvvOxhDIl92rGH0Q/Wfno1rTph8mjWvE4MtXXmYBC Z0zB5i1H3DdhJ7yowoojaHrBEQX3MDDK7jenGFOjYXg7Jk5rJVNFqQ9PqJajE68TSqhW ko/CjXc4H3lw4erf+wRBlUlpiT0sAeXqhI+mYX0JSN9TL6FpqeSkMXWU4LlC0Xe/IPzz a9vQ== X-Gm-Message-State: APjAAAUNZx+woYbA7Iy+b8jyFIrClIAjPBD4vdRHpktAMqaEXrtxZbJ8 EAprZWj5K6Xvj348sgP+gc4bhZgGao06gKqb X-Received: by 2002:a63:ea0c:: with SMTP id c12mr8215049pgi.375.1557303805817; Wed, 08 May 2019 01:23:25 -0700 (PDT) Received: from hjy-HP-Notebook ([2408:84e1:e1:11f1:d099:a352:1690:3163]) by smtp.gmail.com with ESMTPSA id g24sm24565424pfi.126.2019.05.08.01.23.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 May 2019 01:23:25 -0700 (PDT) Date: Wed, 8 May 2019 16:23:19 +0800 From: JingYi Hou To: Darren Hart , Andy Shevchenko Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fix double fetch in wmi_ioctl. Message-ID: <20190508082319.GA8817@hjy-HP-Notebook> 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 There is a double fetch problem in function wmi_ioctl. After second fetch overwrite the length to avoid this. buf->length is not used now,but it may in the future. It is good to get it fixed up. Signed-off-by: JingYi Hou --- drivers/platform/x86/wmi.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 7b26b6ccf1a0..628b9730b4d7 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -823,6 +823,7 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) struct wmi_ioctl_buffer *buf = NULL; struct wmi_driver *wdriver = NULL; int ret; + __u64 length; if (_IOC_TYPE(cmd) != WMI_IOC) return -ENOTTY; @@ -833,24 +834,24 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) mutex_lock(&wblock->char_mutex); buf = wblock->handler_data; - if (get_user(buf->length, &input->length)) { + if (get_user(length, &input->length)) { dev_dbg(&wblock->dev.dev, "Read length from user failed\n"); ret = -EFAULT; goto out_ioctl; } /* if it's too small, abort */ - if (buf->length < wblock->req_buf_size) { + if (length < wblock->req_buf_size) { dev_err(&wblock->dev.dev, "Buffer %lld too small, need at least %lld\n", - buf->length, wblock->req_buf_size); + length, wblock->req_buf_size); ret = -EINVAL; goto out_ioctl; } /* if it's too big, warn, driver will only use what is needed */ - if (buf->length > wblock->req_buf_size) + if (length > wblock->req_buf_size) dev_warn(&wblock->dev.dev, "Buffer %lld is bigger than required %lld\n", - buf->length, wblock->req_buf_size); + length, wblock->req_buf_size); /* copy the structure from userspace */ if (copy_from_user(buf, input, wblock->req_buf_size)) { @@ -860,6 +861,9 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) goto out_ioctl; } + /* Override length in case it is changed between two userspace fetches */ + buf->length = length; + /* let the driver do any filtering and do the call */ wdriver = container_of(wblock->dev.dev.driver, struct wmi_driver, driver); -- 2.20.1