Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2569629lqp; Mon, 25 Mar 2024 03:01:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfQVSpcJpds1XqI2vDeoJs2rvjrJqEcXLVdPo/Px83dHYZnCzEcw4uWnsDALwmgFcoXIDpqIE1vKKib48CFz+KKNZgoItwTdLFeNPPYw== X-Google-Smtp-Source: AGHT+IGDknfDewtTzc8i72txIrog22II/TDhowA03ZzeWXpqvZXUUyD2W3WPR2FNZj6r+6InWqe4 X-Received: by 2002:a92:c605:0:b0:366:c47d:3844 with SMTP id p5-20020a92c605000000b00366c47d3844mr6536274ilm.21.1711360871585; Mon, 25 Mar 2024 03:01:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711360871; cv=pass; d=google.com; s=arc-20160816; b=MLdtWyq/dc2T471rARMakOekiy8pclD4s0pYBaT4Ks2pjd0aHtuHPPH0Nr0rSVOeJD /zj/zS1m/aJThDfMqRxce/zDANT6Nc5Eu3mAW8oJ+JvrYLSv7V+ao0fwS7KbDCQi69Bk 55tw4xqx7iJY9BBg3+m1XHhNUFXLTDsN2hIlcU8fb2tqAK7sJtpEK0kLolgP8XY3sVLR /qcvmkYHikdYYG/yd2i8NXpYVXWKyqWyTjOD+3ewBQc50QoDvDPAK9/NHAzJM+MMMmsM UKnnrnacxQUyLrti3VX6cTIFDwrn4aHE4kZ4TS2IGehQNNJyn9sV75pn4Aacf8mxm9G7 wFgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zeqAzF4VM0rpLgTNGw+IZgvFx3INxo/WALWKXDQ0Ojg=; fh=6+9f8U16DeY2SD9AQ5owd8paFMl9NCtcHFp7+/0usyI=; b=BP0AVnrE4gOlBFLdBun5ANRkHviRu8UzsmjUSXq4k+q4bv6rycKN8DKOI7+R52h9Wi x6dQTC3ZfaTRTrCskh7CVXkxvC8OQgVAaHqKqBdOP3YHl/mYGNa/KmW1seJlj5YjBSK2 LbTII9Xvn94T57xc4z7Z+44lkzfEqYnANGTfoGy7ZPlLNnPwH2tRGVXjaaCQzVLemwMQ 4VqUfqX895hbFBtJL1FCjq6H0klYLyrjooFPPSingR6Qr++IxoMSereITp/HNxVJLcPE U8ialHgHd90qRQL51tnm2wvEcOsBL6DPes4z2MSG5d9zDrcwvAtjBMMSGVd15sNy526+ pPcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h+eF0dKF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115978-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p30-20020a63741e000000b005cfd6ba16f7si7042847pgc.647.2024.03.25.03.01.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h+eF0dKF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115978-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 013ED29E960 for ; Mon, 25 Mar 2024 09:57:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECA32170A5B; Mon, 25 Mar 2024 03:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h+eF0dKF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABAFC234530; Sun, 24 Mar 2024 23:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322284; cv=none; b=YQChpZXKtIYix8fawVP5iAb4So4MEEuC+SSzFFDUEpvylPp/UjrmpwcUQHlByFfvvwbnDjj+yhvlXZMVThbTnIixJF8cjyCXQ/WBPFc6kJjGEsGTr5U1QBBdyEM7aTyNOFqsFt9wTJ/Eam3Imp7ZiX361zl+Q7EikOr7UTEHe2E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322284; c=relaxed/simple; bh=DnIEbnQD9ob1MO8/v30ZkD/ZbTdidfNE4UviQRjCoEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z8eiC7FPS3vpFssZF9Q0+y169OxWUboDIYM7rWijOiV8JGX6emJSQrnp6dD2G6WEOZzgK08uSkq+eerxLZlygAalY7b1C+GKI1AF78vGYrdQxQr0tRDO8SmP6CoIEbtEt7IfCc2LnN/4rGBPn/tYts6sA+0GSR44U76Bv0qw/Uc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h+eF0dKF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F173C43394; Sun, 24 Mar 2024 23:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322284; bh=DnIEbnQD9ob1MO8/v30ZkD/ZbTdidfNE4UviQRjCoEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h+eF0dKFvdC9b1LdumtKmc9LR2ZSBink7sC32jgmQ+u4cXcck3zNlr26G58vmG557 6EhQcGw2+FvO5hgdyqhD+qz/3B22Gz+v4sFyt+L+P/w3BpxFnlKgqQ8TNXpLbKO+6S rooB8c/BdpVwqtGvOwHRnmBcKSte+44mQKQXKGX49s6npUsPem+I/48Y2exFkuXs3f TOGSNuh8u/pKnS+mOSuQulw4Y1jRHhbCzUgMcjgq2auZ6mSeF3gwq50giZZHsvR39A D3WvkeZRz2aI3UB2Anhsbqj2OU70Ps1p6UuuAxRKj0u5NYD2lYONPoKB3LWDBRoKg8 dpRJjx4O5Nrog== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexey Kodanev , Jack Wang , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.1 367/451] RDMA/rtrs-clt: Check strnlen return len in sysfs mpath_policy_store() Date: Sun, 24 Mar 2024 19:10:43 -0400 Message-ID: <20240324231207.1351418-368-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Alexey Kodanev [ Upstream commit 7a7b7f575a25aa68ee934ee8107294487efcb3fe ] strnlen() may return 0 (e.g. for "\0\n" string), it's better to check the result of strnlen() before using 'len - 1' expression for the 'buf' array index. Detected using the static analysis tool - Svace. Fixes: dc3b66a0ce70 ("RDMA/rtrs-clt: Add a minimum latency multipath policy") Signed-off-by: Alexey Kodanev Link: https://lore.kernel.org/r/20240221113204.147478-1-aleksei.kodanev@bell-sw.com Acked-by: Jack Wang Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c index d3c436ead6946..4aa80c9388f05 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c @@ -133,7 +133,7 @@ static ssize_t mpath_policy_store(struct device *dev, /* distinguish "mi" and "min-latency" with length */ len = strnlen(buf, NAME_MAX); - if (buf[len - 1] == '\n') + if (len && buf[len - 1] == '\n') len--; if (!strncasecmp(buf, "round-robin", 11) || -- 2.43.0