From patchwork Mon Jul 12 06:12:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 475593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89604C11F72 for ; Mon, 12 Jul 2021 07:30:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7003861242 for ; Mon, 12 Jul 2021 07:30:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240127AbhGLHcy (ORCPT ); Mon, 12 Jul 2021 03:32:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:43440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345173AbhGLH3m (ORCPT ); Mon, 12 Jul 2021 03:29:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3151611BF; Mon, 12 Jul 2021 07:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626074755; bh=5v7pvtEmxramajIUD60466c9hCUEwDcpp6R/sNavWag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sy2VidSByOzicDJ2Ntb5sIX24Auv99kq5AMp8Kq6a5LtHQpUu/90RQ3NGBIhfTJa1 PA4IA1j8NeViKlG8GVFvH9ucjPtxNiHiCpCiHEnlqawT0/LqlwYunO8VUrribazA4i eHa3m/k4dgS5kyUDPalT5JzXOMl7uaoSj2dzR/vs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Himanshu Madhani , Javed Hasan , "Martin K. Petersen" Subject: [PATCH 5.12 687/700] scsi: libfc: Correct the condition check and invalid argument passed Date: Mon, 12 Jul 2021 08:12:50 +0200 Message-Id: <20210712061049.036167790@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Javed Hasan commit 8f70328c068f9f5c5db82848724cb276f657b9cd upstream. Incorrect condition check was leading to data corruption. Link: https://lore.kernel.org/r/20210603101404.7841-3-jhasan@marvell.com Fixes: 8fd9efca86d0 ("scsi: libfc: Work around -Warray-bounds warning") CC: stable@vger.kernel.org Reviewed-by: Himanshu Madhani Signed-off-by: Javed Hasan Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/libfc/fc_encode.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/scsi/libfc/fc_encode.h +++ b/drivers/scsi/libfc/fc_encode.h @@ -166,9 +166,11 @@ static inline int fc_ct_ns_fill(struct f static inline void fc_ct_ms_fill_attr(struct fc_fdmi_attr_entry *entry, const char *in, size_t len) { - int copied = strscpy(entry->value, in, len); - if (copied > 0) - memset(entry->value, copied, len - copied); + int copied; + + copied = strscpy((char *)&entry->value, in, len); + if (copied > 0 && (copied + 1) < len) + memset((entry->value + copied + 1), 0, len - copied - 1); } /**