Return-Path: Received: from mail-eopbgr80118.outbound.protection.outlook.com ([40.107.8.118]:20389 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1839533AbhCCIKf (ORCPT ); Wed, 3 Mar 2021 03:10:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LE7uPPei3pDKYvFuD2and2YbYh4wb+vRfmPRdlXkWng=; b=YKVw0rmMIWw/Pea2mYQ2XQBC3jtBKFhJlCGQ6Pt4z+YknoJieh9N9iVI+ddWbtQVJoXZ+NLxuoB3QlObql6H5sQWv1C+DqlOZ30trgAHkxJ90GgxHozYowwwtDl7nyzBY0XUTxJgjmxNlZtflMKoR5FGUqDAGFrzemzmyXEt4SQ= From: Rasmus Villemoes Subject: smatch and copy_{to,from}_user return values Message-ID: Date: Wed, 3 Mar 2021 08:50:19 +0100 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit MIME-Version: 1.0 List-ID: To: Dan Carpenter Cc: linux-s390@vger.kernel.org, smatch@vger.kernel.org Hi Dan If you look at vfio_ccw_mdev_ioctl() in drivers/s390/cio/vfio_ccw_ops.c, and vfio_ap_mdev_get_device_info() in drivers/s390/crypto/vfio_ap_ops.c, there are examples of functions that can both return -Esomething as well as may return the return value of a copy_{to,from}_user directly (i.e., in case of error some positive number). [Those "return copy_to_user();" should probably all be changed to "return copy_to_user() ? -EFAULT : 0;" - cc'ing the s390 list in case the maintainers want to do that.] Can smatch detect such cases? I seem to recall it has some concept of tagging a function as "returning -Efoo or 0", so it would also need to know that copy_{to,from}_user does not return -Efoo. And it also needs to follow the control flow, so ret = copy_to_user(); if (ret) return -EIO; something_else; return ret; /* this is 0 */ doesn't trigger. And there's gonna be some false positives around signal frame setup, which do a lot of "err |= foo(); err |= bar()" where foo() report errors as -Exxx and bar can be a copy_to_user(), but in the end err is only checked against 0. Rasmus