From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F19E534A796 for ; Sun, 3 May 2026 18:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777833991; cv=none; b=V3JlRtbA+aTCPgr0Q8qkPT8X2OV4hqDIAMq+8x8hQMRZ6e3eQPPhLptgIR2Txasy041DBhRI2h4cDo+kNr8WWIkf7G9UNIk1fhyDCe+Z9JwXkvMZiv4WbTkUuuGcYkQGv8dbRKJ9Ja2ZKilxd7i3HHR5K8qL2RN5r2K5676sFcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777833991; c=relaxed/simple; bh=hXqSns0mZXRsTyQvYM1QQtbBtCTGXJw/NDYOYiyyiuI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BtPCgVuTGUVXyrTTl3gc9eezLCeuUaKEAAQukXPF2s90bnGOGvvCeQbQykVXsdp/SMruUElzXKL1lkVenNsZGwpFcQqsnHsw0ptuZN0Hy2CLn4b2cSfJ9FI235gZe7Vi4EWPF6XeloMWeQqxE6Z9O53GQEkc5hZUkF24Q8y5hmE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82418b0178cso1600979b3a.1 for ; Sun, 03 May 2026 11:46:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777833989; x=1778438789; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i2HxLSSoyWjc7srvpQpGKBdhtVDS99Q1hYlUtIuh62k=; b=sayofHQE7u7NCCdiGg8c8rYL0E6slusk7skn/eteTiQHa1Nt5Opb7Iu01CIaeg8w2H TAAC82mUo8XVn0ySow+lny4g1wLfXkwmXh/VR3a7diF6YMGzVpOz2ZuFnxvYuuqgi5ZN 3vVyd3a+1Q26wfMlt+6AbGFtH5DwLx9hjPYDWnCmtpEtNI0xNBD1zIbP0MeTucekKBLK MXYzWJ8SHlefviqrnIq6r/DEqaTpLDLh2MoHR29POOEO4xO7HlqlOZLoGL440YFxB3uy S7ot5bek8W7WP9h2Nd4HJRbWiu8spN/1HG4qHRnEso17A2ypPaXoBxCQs5jmWP9liIhE 6wlA== X-Forwarded-Encrypted: i=1; AFNElJ/AkGMzm6pKF5n55CZoWbLCqpKNwxl2/qYmhN3sMOOXzJYi2dj82ol6w7KxeeCvMXjS5Cv97m/L7sPnHJk=@vger.kernel.org X-Gm-Message-State: AOJu0YyaDi5lQntOOkSOBxeKWcDQCGbSKR/FnFkjj8DET8fddUhfZ41C nIJX7B+OEkCCgF5V8+0ARlcYuO2Q+1TOhEO3NsibIPelDo/0WiFq5H0q X-Gm-Gg: AeBDiesOR0+AfRz8238TSGvT9T9KwntdjHbSqogB1yxogv+cQ454RDPC3kJN9rj+rVs 67U2sUGvQ+4VhgJdu83g7Lo1l8yMBGripqI+Yity488dQ+yevqT1AQaehHOlc7V4Xm/20ZKsM9+ ZfbuP2V5MrIdgp5zYnrOf37S+0LfWruh5gIulmLEILoddpwB+9+8zw9zLcalvAI+SJC+ef1wLZX v3BY9F2nRqqH/+2LtGi7AAgcdfQvIyUOu6dXMBMDBN+iP7ZMLsuv36dFKvXb9BHBQ9iiyIOssTT Puhp+mkti8CkhkKJt7sb2wdODib1y/QTW5CV149WN1oJFZPqJiCymn3+FiLyOcOQUy1QKxUo06m gr1dK2F68o112JVS1LY6GP8v7B2/RzVroRVG5AAyCfjlpkYwTiRO4BbEqBrH3gef4cjtuDEFuG8 GPbz4tmUQiVweYBf6Voet/mOIiD67D7FF4JxpIj4PacXvKucZqUOJVk5jOh0wNj+CN1dowF5zDu 34GcKfOwJYlbWbs3JmKEii/oTKBq2/J+gf2CZ97WAU841zR/vNZImltuRetbYp+4Z0i6oAiODLD RaXWw229QsiBAEXe76Eqp8rp+mxCTsQo6N4U8AVvbA== X-Received: by 2002:a05:6a00:bd0d:b0:82c:212a:a9b5 with SMTP id d2e1a72fcca58-8352d24425fmr6654243b3a.36.1777833989242; Sun, 03 May 2026 11:46:29 -0700 (PDT) Received: from localhost (fpd11144dd.ap.nuro.jp. [209.17.68.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-835158bc863sm8514553b3a.26.2026.05.03.11.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 11:46:28 -0700 (PDT) Date: Mon, 4 May 2026 03:46:27 +0900 From: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= To: Deepanshu Kartikey Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com Subject: Re: [PATCH] PCI/proc: check __get_user() return value in proc_bus_pci_write() Message-ID: <20260503154557.GA1455207@rocinante> References: <20260502011446.125268-1-kartikey406@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260502011446.125268-1-kartikey406@gmail.com> Hello, > Check __get_user() and return -EFAULT on failure. [...] > @@ -136,7 +136,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, > > if ((pos & 1) && cnt) { > unsigned char val; > - __get_user(val, buf); > + if (__get_user(val, buf)) { > + ret = -EFAULT; > + goto out; > + } We could move to get_user() here. This would allow you to drop the access_ok(), too, as get_user() would return -EFAULT on error. So, something simple, like: if (get_user(val, buf)) goto err; > +out: Use "err" for a single goto label for the error path. > pci_config_pm_runtime_put(dev); > - > *ppos = pos; > - i_size_write(ino, dev->cfg_size); > - return nbytes; > + if (ret > 0) > + i_size_write(ino, dev->cfg_size); > + return ret; This can be kept simple: err: pci_config_pm_runtime_put(dev); return -EFAULT; The i_size_write() is such an unfortunate band-aid, but unless we have a way to set the size before the procfs entry is created/made visible, then the problem that this aims to fix is here to stay for now, see: ecb3908046ce ("pci: write file size to inode on proc bus file write") Having said all that, since you are looking at proc_bus_pci_write(), then perhaps an update to proc_bus_pci_read() to use put_user() would also be prudent. Thank you! Krzysztof