Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp714751ybi; Tue, 16 Jul 2019 04:13:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMR719dux8FkG8DDSczX4XoUDI8MqD2Hoe2dKAXZTHWWFLJlIYmHHZqScEUk/mLIb4vD6b X-Received: by 2002:a63:ec03:: with SMTP id j3mr5489166pgh.325.1563275591890; Tue, 16 Jul 2019 04:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563275591; cv=none; d=google.com; s=arc-20160816; b=TUkGh1U1aZanP3apAjirxak2hI7GJc27TOVvZ0g/fl6C18biOX0q+yAJEDvcJLgPPz MoYCKYzU0QN6XdHXjBFQZKSJ2ZzU5LX0mHtHW90oN/7JnRvOzpHFoobV4FJbxlMQDGk5 K7cjUQX3byxDUuJ9GODwAKyUrrG7GudzJ2cqcC4WeZkYclhBBE70WHZe8ZoY/yvVkKtL P0r/X2y3xxrQ5v1zZhit+6R5Adtn+N1npzaZAamRUCh+Dm/6SdVpslzG0wdi92i6DRdc IBzwgYzojjzCgSIBQEIUaEGo+N2BooLd5oWOsjWbeOp9eBAFi1OZAWZXGFrWdpwNjf6g J5TA== 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=tG4oN7QUyXBM9ONfLmraVG6pWQWDU28XTB/o4iOsC64=; b=SZ7typFM0bwbKW5SoE/3xxuf/utOLxrCBn70KFStXncDrhK2/M3PPVCbryF70R8UkT 1syUdYyYRa3UxX64IHatLc6a28Hp3jv3aquwG7fPYnGiW3XxDpyIq17MYG7ZCzlzqJDU 1oZPJycjjwrCtb/TcJtzdAvwE7w5VixDbmLm9z7JKA76Q7298GnjubESLRP37SFM6CGL YV6Y1RSGsXBvaI1WfADIxwiefqaldWbGX8ZqvvgpBxfVvh8WT1QSiHC4bmFVvtTr/jQi f6dLxEhMmfQQxckDlYkAkbpEEnbsKa/1S7no7qBIcNwqUmc5s5gqjiknswcvgSnNW80g +6Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lCtz0JYS; 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 f9si19722939pgg.450.2019.07.16.04.12.55; Tue, 16 Jul 2019 04:13: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=@gmail.com header.s=20161025 header.b=lCtz0JYS; 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 S2387606AbfGPLL0 (ORCPT + 99 others); Tue, 16 Jul 2019 07:11:26 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45361 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733200AbfGPLL0 (ORCPT ); Tue, 16 Jul 2019 07:11:26 -0400 Received: by mail-pg1-f193.google.com with SMTP id o13so9260716pgp.12 for ; Tue, 16 Jul 2019 04:11: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=tG4oN7QUyXBM9ONfLmraVG6pWQWDU28XTB/o4iOsC64=; b=lCtz0JYSz/PN5ckXRERy5AhE//7W2BwCQ5+3jNGJLYSoc6xU4cGFZVKPCTcwZPDPde ZMAQNppd4iZ/2+BxXt9OqQAob7W24AQe8KeMnseH7Ix83ZM5Kl9it6WcPSTJLmMErMz/ jKY4LWMLzCGtGDexq48mmnbjGK1AFtrvOOUoYnTRXteWT+KVoBoCGshkqRYACoPC7D1K COyc+MfsbAinmNXL/VXcywePCUgFKvch/hWkefQpW1jj5Q5CbEGGACfPr5Fm+Bsn4/XU Er41rmbDvQBW/5uOwpmYCUfFmefUg3m1GGvywEZnR3K0rufXC1kTEVNbp5TeB/DzZcZY e6gQ== 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=tG4oN7QUyXBM9ONfLmraVG6pWQWDU28XTB/o4iOsC64=; b=Y+nHhxZbmyMEyaHt4EaqluXcsMeG8Ev5uUAYO4q6/lb98OzqV3h41+AKrTkZEfQx33 nSjHgj+iRF19gy/eib1szMbfrdjtrf6Or+v6be6IZsQqAKbm6UKsBFAXBJweRm45l5ev E5lv0Vz+KQOdvm0HJH/MtQ7TdHsag8YRnCEFdJIxSff8rnWycUgdebCo90RVqWr4VGsP ywCwheR7hNmiVEEnZ16BbHgXb5Rd0yVJMODDHnnssg7q7MZxreI4ciGRTsSKdUqj0frT 3fsWqNb0AgKo5/hP0BuiZDn+g3gcaPMw54aT8+tD/JACtr7vARjjLE4SuBWinweCnOeY Mw+w== X-Gm-Message-State: APjAAAVZa839+vFFsIFgtHGqS6NRQmJEQYpKmnBOqCC+Go6bXL5RWsRk iOrtisAbKOaTxI2qTrL8bSYnen037it2olqu X-Received: by 2002:a17:90a:3401:: with SMTP id o1mr35150615pjb.7.1563275485431; Tue, 16 Jul 2019 04:11:25 -0700 (PDT) Received: from ubuntu ([101.198.192.11]) by smtp.gmail.com with ESMTPSA id i9sm16978531pjj.2.2019.07.16.04.11.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 04:11:25 -0700 (PDT) Date: Tue, 16 Jul 2019 04:11:22 -0700 From: JingYi Hou To: alexander.deucher@amd.com, christian.koenig@amd.com, David1.Zhou@amd.com, airlied@linux.ie, daniel@ffwll.ch Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/amdgpu: fix double fetch in amdgpu_ras_debugfs_ctrl_parse_data() Message-ID: <20190716111122.GA35069@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 amdgpu_ras_debugfs_ctrl_parse_data(), first fetch str from buf to get op value, if op == -1 which means no command matched, fetch data from buf again. If change buf between two fetches may cause security problems or unexpected behaivor. amdgpu_ras_debugfs_ctrl_parse_data() was called by amdgpu_ras_debugfs_ctrl_write() and value of op was used later. We should check whether data->op == -1 or not after second fetch. if data->op != -1 means buf changed and should return -EINVAL. Signed-off-by: JingYi Hou --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index 22bd21efe6b1..845e73e98cd7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -233,6 +233,9 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f, if (copy_from_user(data, buf, sizeof(*data))) return -EINVAL; + + if(data->op != -1) + return -EINVAL; } return 0; -- 2.20.1