From patchwork Thu Mar 31 21:55:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 12797722 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 6DB79C433EF for ; Thu, 31 Mar 2022 21:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242122AbiCaV6s (ORCPT ); Thu, 31 Mar 2022 17:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241964AbiCaV6r (ORCPT ); Thu, 31 Mar 2022 17:58:47 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A56630F7A; Thu, 31 Mar 2022 14:56:44 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id a17so830699edm.9; Thu, 31 Mar 2022 14:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KeYUo5Rxtop2eZuKjtBKuva+XDteBCoX0CO2d3I1o2A=; b=Yk9NZ/50RFQdHnGdTItCs5XLEfu2j/9wx2Krv1F8waDIhUFBxkcr/3u7D3n2vmQpLN V2UnoOLGBqi25p94TtB1OOu9wOKMfcLiCDq0pBNS/gZJFJO+mZhP3oAMMNmEUQhiQfKO YrlZEIDX9qqd0I9rbolh4TrcqbhhBcRrcmjIS8O5pyeXnZarS485ZWAKJosEqGO3BG/u e10q8Fi21AM2ICtCEzO+UBOM7VqAeGfetXl6bKWIi4Kx7vIMWd2H4YF6SZzcgX6t1ppE SwLL98IGJEfdjwC7pEiVHGcdu0ifUs0467RFiVvQDXEc+MkRI6DG3e57KyfQhpuz2iPa SdAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KeYUo5Rxtop2eZuKjtBKuva+XDteBCoX0CO2d3I1o2A=; b=rvUdgoevuJjnK2BSr+8H6gCM/FnJ7UrEWUkaA7JjmfiSH1qfq4wE+kQj8BefAYSSDr Y0Ay45csXMM4GzJiwlCqNMhGSBTF5KfjjVsCaQ8AxqmsR9qt7HcRV6Jvj4CV6kFxUaHN BH1Vwe8KWUYjvkhbLvjtx2gEVC1Kj4CZgJzq5ZY9GLdG8gOHYY9Y7T9AUE7oUWrBZYTn z40xMmNS6S/+0vl6iQbi02gx060bYsQZr40PCzi/nd1DQXSOJWgPK/lTvqAO2pBXR1iJ 9SSBdnKUl7hvh7aLdFhK9zSBKegYR6YigZUBSxam64z293lHJFqjg2kknP1oQTXLXDV7 wGGQ== X-Gm-Message-State: AOAM532YX5QNIa8zk+mtDyc5CKvUDv0Wxbih8UdicL0MoIla+HTmFJsH bPqGW7bvb4SvKv/Y5F/KwIE= X-Google-Smtp-Source: ABdhPJyONxCDb77pIW8ufJNOJ90VzxBr+yTgi+Y1i1NLHsjGazEEm2WeSQZh+WzkZH5N9StrRYvzkQ== X-Received: by 2002:aa7:d398:0:b0:419:d011:fe8b with SMTP id x24-20020aa7d398000000b00419d011fe8bmr18763741edq.168.1648763802902; Thu, 31 Mar 2022 14:56:42 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id s24-20020a1709066c9800b006e490a8cf71sm251434ejr.4.2022.03.31.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 14:56:42 -0700 (PDT) From: Jakob Koschel To: Steve French Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH 1/2] cifs: replace unnecessary use of list iterator variable with head Date: Thu, 31 Mar 2022 23:55:40 +0200 Message-Id: <20220331215541.883746-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator variable will *always* be a bogus pointer computed based on the head element. To avoid type confusion use the actual list head directly instead of the last iterator value. Signed-off-by: Jakob Koschel --- fs/cifs/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 7e7909b1ae11..4ac86b77a7c9 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3858,7 +3858,7 @@ void smb2_reconnect_server(struct work_struct *work) tcon = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL); if (!tcon) { resched = true; - list_del_init(&ses->rlist); + list_del_init(&pserver->smb_ses_list); cifs_put_smb_ses(ses); goto done; } From patchwork Thu Mar 31 21:55:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 12797723 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 7B1B4C433F5 for ; Thu, 31 Mar 2022 21:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242154AbiCaV6t (ORCPT ); Thu, 31 Mar 2022 17:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242077AbiCaV6r (ORCPT ); Thu, 31 Mar 2022 17:58:47 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB20241B5C; Thu, 31 Mar 2022 14:56:45 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id pv16so2192630ejb.0; Thu, 31 Mar 2022 14:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xkr0PQO//o59RSxUJyyli+qBLYdHF3Dtr2QvlIoMNhs=; b=g5npxspDJVN7vb08r1+5lxuzHg3UsjA7ebp65WyBPtjQCXFAmTeuarZxWgLvAYOO/U D/IHYWdDBm7ZJc+/wt0/tVICYbQcsJRkDUXJEp+1JD9KGiZyoBw2JN+NdDoly1zRDmQ2 gUSlVc0bccrCX4+DXGcE9CY3iGyRzN4JZUQzlHAajrcbfmMj1IhynbNKYu+4s1yDauqu NOuze66qApXULkhoSjOktm3IgP8GIAH11VHz+kDI8y9/q0E/Woyjku78qxk4rr5RfsPP rQze4WaYJSptnA/NcWCml/S6DN2YU012spFZlQYDuYT7sAb+lkBnKWypCyNryrtkPTkH 4HDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xkr0PQO//o59RSxUJyyli+qBLYdHF3Dtr2QvlIoMNhs=; b=pNVDlhQCHOYu07+0cHbKnVtgtk7QNzYGUvfi/yRa8Q+nYe6s73iXTzPrlnX4iR4dg6 PkYoTIoYHwxd3jFqCdOBUFNe64Plf1XaY+332L3NFeRSvYmfRZOnWZYuZVR+azPZpQt1 Ovmj9SHWkLID0jThzwPncLg32uJBf7W42GMrzwTKlvCCpK+H//4Ru++P4Hk9Y3uzBFHc mWbnStbOTm+Y5+xJPO5oGq+YF7ihnSeZejo4Nh+fyRbNxdzUsV8zNgf4cr3DKm5OZ+L4 /566tUbHQ8Q5d3kF+sJeLmXmL1eHpe2vPX+x+7hqBGNz1YSQUgr348+dqkvLhY1Zr3xq fHOw== X-Gm-Message-State: AOAM532Xlr0JWovyEBiiFUavs1XBsp98UmAVVfgR3nCki4/R+DJ8E4Z8 0n+epgP+hSRXguXMUwjK0f0= X-Google-Smtp-Source: ABdhPJwCu1E99glbIhrkJCTMPbFw5eaA1LSX9HxIKQqeRbbdCExVGLRsjJ+QkySEmU9Sepx/PUTYaw== X-Received: by 2002:a17:906:5ad6:b0:6e0:1799:4a15 with SMTP id x22-20020a1709065ad600b006e017994a15mr6950703ejs.594.1648763803671; Thu, 31 Mar 2022 14:56:43 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id s24-20020a1709066c9800b006e490a8cf71sm251434ejr.4.2022.03.31.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 14:56:43 -0700 (PDT) From: Jakob Koschel To: Steve French Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH 2/2] cifs: remove check of list iterator against head past the loop body Date: Thu, 31 Mar 2022 23:55:41 +0200 Message-Id: <20220331215541.883746-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331215541.883746-1-jakobkoschel@gmail.com> References: <20220331215541.883746-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member == head, using the iterator variable after the loop should be avoided. In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- fs/cifs/smb2misc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index b25623e3fe3d..2d862291fab9 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c @@ -150,16 +150,18 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr) struct smb2_transform_hdr *thdr = (struct smb2_transform_hdr *)buf; struct cifs_ses *ses = NULL; + struct cifs_ses *iter; /* decrypt frame now that it is completely read in */ spin_lock(&cifs_tcp_ses_lock); - list_for_each_entry(ses, &srvr->smb_ses_list, smb_ses_list) { - if (ses->Suid == le64_to_cpu(thdr->SessionId)) + list_for_each_entry(iter, &srvr->smb_ses_list, smb_ses_list) { + if (iter->Suid == le64_to_cpu(thdr->SessionId)) { + ses = iter; break; + } } spin_unlock(&cifs_tcp_ses_lock); - if (list_entry_is_head(ses, &srvr->smb_ses_list, - smb_ses_list)) { + if (!ses) { cifs_dbg(VFS, "no decryption - session id not found\n"); return 1; }