From patchwork Mon Apr 11 18:07:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 559794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D036C433FE for ; Mon, 11 Apr 2022 18:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349053AbiDKSKQ (ORCPT ); Mon, 11 Apr 2022 14:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349049AbiDKSKP (ORCPT ); Mon, 11 Apr 2022 14:10:15 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807B537A87; Mon, 11 Apr 2022 11:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649700480; x=1681236480; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YUx+7TS3T7WKp9bH0u+RWM0zj399AI31rwxf9iB4yJU=; b=gYj52TCeUaYHJ3+bGTqJeWM9k8sv/Cy0sIZjkynO8ogngoZicXW3Agp7 +/9aBy3KC7g4SNH64RbdzIzUhkd2Y+zXcXiARuJerSmXrihagLpwsbgxT 1h2pFLbufLOGKrxyHa6QMHB3+VFgba3gs3rSQQ5Hs5RgOXiNIp+HFgbnG jdiED7eLYGdGLtL7PUx7BjwKZWlhhOHpSedTF+ceLqCrKr9+znpaaQEfd Z4S5w9TNQI+ZQalEElbODBrlSHyQGvmuuHYUk2+aZPu2wIS+j7MhJ0g4p 9C+2Fag0r1asCXeEMt2po9sE2D6mc71R+fVGR2imDykwTJmaRgnnIsKFk g==; X-IronPort-AV: E=McAfee;i="6400,9594,10314"; a="322625777" X-IronPort-AV: E=Sophos;i="5.90,252,1643702400"; d="scan'208";a="322625777" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2022 11:07:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,252,1643702400"; d="scan'208";a="654732505" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 11 Apr 2022 11:07:57 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 350DA144; Mon, 11 Apr 2022 21:07:56 +0300 (EEST) From: Andy Shevchenko To: Jakub Kicinski , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfram Sang , Andy Shevchenko Subject: [PATCH v1 1/2] i2c: dev: check return value when calling dev_set_name() Date: Mon, 11 Apr 2022 21:07:51 +0300 Message-Id: <20220411180752.36920-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org If dev_set_name() fails, the dev_name() is null, check the return value of dev_set_name() to avoid the null-ptr-deref. Fixes: 1413ef638aba ("i2c: dev: Fix the race between the release of i2c_dev and cdev") Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-dev.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index cf5d049342ea..6fd2b6718b08 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -668,16 +668,21 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) i2c_dev->dev.class = i2c_dev_class; i2c_dev->dev.parent = &adap->dev; i2c_dev->dev.release = i2cdev_dev_release; - dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr); + + res = dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr); + if (res) + goto err_put_i2c_dev; res = cdev_device_add(&i2c_dev->cdev, &i2c_dev->dev); - if (res) { - put_i2c_dev(i2c_dev, false); - return res; - } + if (res) + goto err_put_i2c_dev; pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); return 0; + +err_put_i2c_dev: + put_i2c_dev(i2c_dev, false); + return res; } static int i2cdev_detach_adapter(struct device *dev, void *dummy) From patchwork Mon Apr 11 18:07:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 560118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E99B0C433EF for ; Mon, 11 Apr 2022 18:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349050AbiDKSKP (ORCPT ); Mon, 11 Apr 2022 14:10:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbiDKSKO (ORCPT ); Mon, 11 Apr 2022 14:10:14 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C80EF2B183; Mon, 11 Apr 2022 11:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649700479; x=1681236479; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=etbDmp0HEg236kvaE9ytGyeBfa0w1hXztgiz7DlpaKU=; b=ANvNFgXqy8WLjtEnQt6k1gOTt5eMr5il26p7+7VESMIlRAxZWaNHkekd pFzLfBGLeCJdrisrkqGwZ6MIZAFwzaWfRApRmPnfN4fopF4DORarcm/I6 Tq+pIw0Aa5diYRNZuraft8+QX3VcWIoggGnrQ6eK9P2untOwy4YebsnDx fLgYeW3FnXxUENLI2AYMh3dQ6pytwNCbLT78Zj6oDfkx5D5qf0fcsXy9s Y8SWAFHrdnqfHDJoam3CCELWM/+TCoi656THQ6CJ+3N5zIS3anuGTA0fX YwSi2P4zPK3lj3ZcrlINWOQrxLGHZttgLh9cWCps8ujrCqsDV/x+nSsPp w==; X-IronPort-AV: E=McAfee;i="6400,9594,10314"; a="322625775" X-IronPort-AV: E=Sophos;i="5.90,252,1643702400"; d="scan'208";a="322625775" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2022 11:07:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,252,1643702400"; d="scan'208";a="572321674" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 11 Apr 2022 11:07:57 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3E15C120; Mon, 11 Apr 2022 21:07:57 +0300 (EEST) From: Andy Shevchenko To: Jakub Kicinski , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wolfram Sang , Andy Shevchenko Subject: [PATCH v1 2/2] i2c: dev: Force case user pointers in compat_i2cdev_ioctl() Date: Mon, 11 Apr 2022 21:07:52 +0300 Message-Id: <20220411180752.36920-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220411180752.36920-1-andriy.shevchenko@linux.intel.com> References: <20220411180752.36920-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Sparse has warned us about wrong address space for user pointers: i2c-dev.c:561:50: warning: incorrect type in initializer (different address spaces) i2c-dev.c:561:50: expected unsigned char [usertype] *buf i2c-dev.c:561:50: got void [noderef] __user * Force cast the pointer to (__u8 *) that is used by I²C core code. Note, this is an additional fix to the previously addressed similar issue in the I2C_RDWR case in the same function. Fixes: 3265a7e6b41b ("i2c: dev: Add __user annotation") Signed-off-by: Andy Shevchenko --- drivers/i2c/i2c-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 6fd2b6718b08..ab0adaa130da 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -557,7 +557,7 @@ static long compat_i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned lo .addr = umsg.addr, .flags = umsg.flags, .len = umsg.len, - .buf = compat_ptr(umsg.buf) + .buf = (__force __u8 *)compat_ptr(umsg.buf), }; }