Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp40508rdb; Thu, 16 Nov 2023 11:16:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVgBnGTxptJLUW+Nb4DV//InFK7/3wqJpmfC+ZwCwnrLrPlOFo69JF84LnI/gCSBuNxdB1 X-Received: by 2002:a17:903:2346:b0:1cc:5920:1d1c with SMTP id c6-20020a170903234600b001cc59201d1cmr4064716plh.48.1700162181816; Thu, 16 Nov 2023 11:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700162181; cv=none; d=google.com; s=arc-20160816; b=oLTZ4fFRjfV4J06JcSG5JQPkwCx7AbFBlW9VzGAtnHZLofDz88FRDrlv9h1qV3KjNS NJSSODNi/b2omgxDj/afSO111EkUdKW8jsWVtYuqbzbBe9DZDwPie3dtGu8KQPtjGMIP 1AU8UTXmKsBH6ERHeh4uHbwvfvR4e/53TJnXhutGLqpQObmrSMgUPVDC6Ki/7QMRTkBv vBB3nX1ox6/m1dtK2T8OcGZcptPAs+13fW9756yPZ+mscNl9By/nwmq8JlxnzAt79Ob9 R8Qv8U1fOpRIV53aeZn6VWiWg9m4WoZvj8d6Ocx2GpsuU83Zg8T1xrsY6nok75jCH4Af bI7A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=xXMlqUa9U+ONyBzylSfeWWc20gFnP/0YsPE87Yq0BOQ=; fh=09bV8Kx0luTQLh0AZEroAqHY6J5w1BPXLlg0Mgc2Wgc=; b=a06yvJITXjgDsLdDbQrHtU0fjfoj2CI0XXmqGvDdjKma5UuS2RaloVe2VGsLpdMGny vs9MBoDk17zWchpq5gwnECvRLHWN/ISHRJjWQBf9+/u5RqZN5zEPVAGzeRgLAsByy0HC hRoMWt8oEbC88ldVD9B+ohRQ7yTXuBLEIFS7fUph/Ouy54qcB/NA+dPiI0vIMzJl556Y RxDvY8hscU808wB2nVSRNE3V5jtgQV6N4E/Levix2ltSUCKfRipUMfyml4r1yY7oRFFY M/iQTvAJKBSAvNNouYoPnZLOFOFDJZ8CkVUfLCU7ekxTB4CqewY5PWj5/z7pSk9r2eFC 84xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PRSE2M1O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id m18-20020a170902db1200b001ce5b99a558si18034plx.519.2023.11.16.11.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:16:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PRSE2M1O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DDAE28032387; Thu, 16 Nov 2023 11:15:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229537AbjKPTOn (ORCPT + 99 others); Thu, 16 Nov 2023 14:14:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231314AbjKPTOl (ORCPT ); Thu, 16 Nov 2023 14:14:41 -0500 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC238D55 for ; Thu, 16 Nov 2023 11:14:37 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b2ec5ee2e4so721543b6e.3 for ; Thu, 16 Nov 2023 11:14:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700162077; x=1700766877; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xXMlqUa9U+ONyBzylSfeWWc20gFnP/0YsPE87Yq0BOQ=; b=PRSE2M1ORVm7fO5vG8Ol92WXrkNFp1x4Oy4Ag4nrtHgrOIrnbZ0jg6YTpNCajdevk5 97ne8VGKG1rug+OceA7nx3KYfmKYTxue2zaKWIrCE87GBPG4NjQwhhubH3IbCIKga0QH s479EnroSES6n+gmAttCGt3lzQsoWatPNMQns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700162077; x=1700766877; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xXMlqUa9U+ONyBzylSfeWWc20gFnP/0YsPE87Yq0BOQ=; b=ijfvyXjNjKM0TMnMnao0KmVPLqH1sSKdpDbMnpf9gURaQiT/7+dVAzcD3WVYQCT3/x YRxc+U7aGeEjsvuBUvoTkv0NLP2dox4Q97LjScsAPoL6ENETHPJrcuzx8flz77Jfjb+D SJuZ97FUo0D+rm65Q+VDSUdDQmND66e+ND3BkYkTjVxPFwDIjAOY92lCCepDi3uCM4CS 0eaGGepTocF2dcJq4Nf4qRQErv7+cRvphz/AWo833RGOhTE0UneWklNEk/+G7iKCuUxP Kjgm5I+aMViSez2UiDXmglXovG0Agcm2bSUA5vPG1fnHHLun0xMX5lcsXGhOkb7K+9vr Re4Q== X-Gm-Message-State: AOJu0YxdGX33l3MBeN3VKsEK7QcvQON1tnKVUcr2jSbLdzZ1kcss5Ccn 0ey/RIZMK7eKH1tLFuBLOSCBlw== X-Received: by 2002:a05:6808:13cc:b0:3b2:e6a4:e177 with SMTP id d12-20020a05680813cc00b003b2e6a4e177mr24284312oiw.51.1700162077185; Thu, 16 Nov 2023 11:14:37 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id y17-20020a63e251000000b005ab7b055573sm47469pgj.79.2023.11.16.11.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:14:36 -0800 (PST) From: Kees Cook To: Steffen Maier Cc: Kees Cook , Benjamin Block , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Azeem Shaikh , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] scsi: zfcp: Replace strlcpy() with strscpy() Date: Thu, 16 Nov 2023 11:14:35 -0800 Message-Id: <20231116191435.work.581-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2125; i=keescook@chromium.org; h=from:subject:message-id; bh=n/5QOMTS/PQ87jfirRVAutDJEB7F5Jn3WLO02CU/Zxk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlVmobOo7x61Ke/67MhKfWOLSNoGNoSj987Uk83 vjr19oRi1OJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZVZqGwAKCRCJcvTf3G3A JnY/D/wJJH1WvSnfcOFsHJ7ya6qtSFf2j4ns7EUFNJSsRvSJTm16bUOEbYBISKfoDSA0nJl9QdC Kq1Kdoo/POkGyIJaVT1ksnnKoo1CaomOCqIXxC0BvUjoUzKGVaRQx3UxVRx1tznTM1srcjzdbDo EL7KzXzBmD2fRaI9tdtxujifs4qF5H8lX7+LlgKiGWD97An4mlPxktKW5vdO0N4n+lNN9pYsC5Y sOr9Lfo9CqR9l0PdxAK+GG7f0orxLMKxpCr/CbjYyR6epEgG430To5caSUabjbcpYum0Eckl4pp AJvL8FPevJbV8mBBh9CGwzuPyUhotxw/mmeq1mMxWqDcCH9WMOwiqOW9exZGun+BT2oba/EjWWM 7doqbdFNhFoCMTx3oBuCpBgzo+grrxYBi8w4gfnqP4ax7K70EnGtmYWbTPkyFWs2L3IEeC2g25j jJmf7RRM9gVipZQG4MEW8qn1RYQR5vxvbDUs8sgKP3QEw6TBzKQ8AdY18O49jUDrsFrYUp8isAn j5DXCRqc8rxHuxrH0RdeEa3/uMOtPNEJUGEOkKQ3/5SZekJBQ0oIUtX5o47qCSUHAzRq6CmNhA+ xUaww+US21aOvGxxpOSr72MJoDcCSgyOWR2Y8Tr75noNYgECiTwUxEgA0Gj+rPi9UcOOB4Fer5V PlWWlQh bp1J2Obw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 16 Nov 2023 11:15:01 -0800 (PST) strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated[1]. Additionally, it returns the size of the source string, not the resulting size of the destination string. In an effort to remove strlcpy() completely[2], replace strlcpy() here with strscpy(). Be explicitly robust in the face of truncation, which should be an impossible state. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1] Link: https://github.com/KSPP/linux/issues/89 [2] Cc: Steffen Maier Cc: Benjamin Block Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Cc: Azeem Shaikh Cc: linux-s390@vger.kernel.org Signed-off-by: Kees Cook --- drivers/s390/scsi/zfcp_fc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c index 4f0d0e55f0d4..1a29f10767fc 100644 --- a/drivers/s390/scsi/zfcp_fc.c +++ b/drivers/s390/scsi/zfcp_fc.c @@ -900,8 +900,15 @@ static void zfcp_fc_rspn(struct zfcp_adapter *adapter, zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID, FC_SYMBOLIC_NAME_SIZE); hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost)); - len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost), - FC_SYMBOLIC_NAME_SIZE); + len = strscpy(rspn_req->name, fc_host_symbolic_name(shost), + sizeof(rspn_req->name)); + /* + * It should be impossible for this to truncate, as + * sizeof(rspn_req->name) is equal to max size of + * fc_host_symbolic_name(shost), but check anyway. + */ + if (len < 0) + len = sizeof(rspn_req->name) - 1; rspn_req->rspn.fr_name_len = len; sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req)); -- 2.34.1