Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp200465lfu; Wed, 30 Mar 2022 20:40:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSWiTBnwcmuV4DNc1u3inPldrn2T9Wj6lIkNZZ1a6ATI9KLVD0c+X2ws1TUCkiyl7HoDwK X-Received: by 2002:a05:6a00:298c:b0:4fa:8e7b:349d with SMTP id cj12-20020a056a00298c00b004fa8e7b349dmr37246757pfb.26.1648698053451; Wed, 30 Mar 2022 20:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648698053; cv=none; d=google.com; s=arc-20160816; b=QMDl64N/9EC9r9oh61uIjDP5BFlD8EFA7bc9MPQH5NdkdKHxBM9x+qSlKQAkmSPGjY MTDoiAQ3jn1Xxom+vlqp0q+4tul2D4A9yZPcbRZrJRJqY7itxhzK89+VHWvcwHDbzsWR X7RUUP8nZ7ksirc4aFaTvjG6MBOHY9izWu4JHf3lGSqtjll96zTRyDkR+Mqn4Lk0Si2U IJBK5Tco21Poh/5htw+YXA7hLsaat87Ht5J21TIKNstj7fwgs0k1MpGZwWlnQZ1Q3FGy u84XIH22iFxWbPzsxoJbXClW5EJ3dZ66V563ZMHcXtZZPOZ2DrJDNgHyNrxRi922P/Kv iMEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y7tbgokD98W+ffF+NFExKaQSIB5bjYjGTkXnH7eOUvI=; b=DAurrELWxOZJjiQJvmjuHZRejBrHzYODQmaf0fLvwgh6Zwe2G9LxRDcP6DepDwAdqC Feu/ijO0N9G3hsT9wPHp568CI9CzaXRKhil1wXzuMvhDhD/fA33i3m2gTedFjhDgz7nk poVzzFAGRVJoNK6kKobCqQwwCLWQNqSNss2+222BQw/iF3/C0WqT+R+KvJjFEEsRAtkx TCt/X4rHhyo0Wq+74sk3bjEET5LrBa7ThnQaz6zlC7j/VeCukyfjWPDHgCl3WN/UgfJe 40fwHu0xaKyMdvKUySEZrktScnjtV5p8kmpmTGz54XlRwf70IQ7hjKepu30y1jQXQWgL e9DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PxKxUdLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e16-20020a635450000000b003824fa8e997si6973926pgm.177.2022.03.30.20.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PxKxUdLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2A0AE6C67; Wed, 30 Mar 2022 20:00:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344346AbiC3MIF (ORCPT + 99 others); Wed, 30 Mar 2022 08:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344501AbiC3LxN (ORCPT ); Wed, 30 Mar 2022 07:53:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEBFF262D69; Wed, 30 Mar 2022 04:49:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 01201B81C38; Wed, 30 Mar 2022 11:48:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9AB9C36AE2; Wed, 30 Mar 2022 11:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640935; bh=qW1x31HnZxqlWv9yLK7leVGiHSRFHxjgpFRqN+3ePM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PxKxUdLdo+N1VBpnDbqseQVPv33pJ+1pX09PlodQnZwLU5OCv8fwC4+gFao1DpAZ9 tzBgTNQTrkyeS2QjMnVg3VUSTw5KmfVcxsbOQlyuzLTtXDrL9/Qi/DsT5eFHHrqqvC GWsa28wYXdl7L/gcrSCdmj9DVpB3fL87ahJxCL94WZK+mbol1ry9EJ1g4y6DNIuS8Q AvHeyA67H6Mni6ZcOQqVhRjHJVheOguvDUNgpoi+ZXf6WBdgSyBiVV/0mJOCRf/nAp oTUbpgL4ciUNp7A22zXgg4X5AzcwYdF+Mv06PVxIy+uMcOz8gTmTPcyRuQeO/HKC0x hx9aQ+MFl13AQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tim Gardner , Antonino Daplas , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Helge Deller , Sasha Levin , tomi.valkeinen@ti.com Subject: [PATCH AUTOSEL 5.16 14/59] video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow Date: Wed, 30 Mar 2022 07:47:46 -0400 Message-Id: <20220330114831.1670235-14-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tim Gardner [ Upstream commit 37a1a2e6eeeb101285cd34e12e48a881524701aa ] Coverity complains of a possible buffer overflow. However, given the 'static' scope of nvidia_setup_i2c_bus() it looks like that can't happen after examiniing the call sites. CID 19036 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW) 1. fixed_size_dest: You might overrun the 48-character fixed-size string chan->adapter.name by copying name without checking the length. 2. parameter_as_source: Note: This defect has an elevated risk because the source argument is a parameter of the current function. 89 strcpy(chan->adapter.name, name); Fix this warning by using strscpy() which will silence the warning and prevent any future buffer overflows should the names used to identify the channel become much longer. Cc: Antonino Daplas Cc: linux-fbdev@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Tim Gardner Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/nvidia/nv_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/nvidia/nv_i2c.c b/drivers/video/fbdev/nvidia/nv_i2c.c index d7994a173245..0b48965a6420 100644 --- a/drivers/video/fbdev/nvidia/nv_i2c.c +++ b/drivers/video/fbdev/nvidia/nv_i2c.c @@ -86,7 +86,7 @@ static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name, { int rc; - strcpy(chan->adapter.name, name); + strscpy(chan->adapter.name, name, sizeof(chan->adapter.name)); chan->adapter.owner = THIS_MODULE; chan->adapter.class = i2c_class; chan->adapter.algo_data = &chan->algo; -- 2.34.1