Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1216667pxb; Fri, 1 Apr 2022 07:38:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygnOxBNXR4xv2Tha9s1PACxyu3lRYTAr7fVy6Mg6N60yVGcqb3fjuZzOQ8onDgPcr6sVLz X-Received: by 2002:a05:6402:254e:b0:418:e716:f987 with SMTP id l14-20020a056402254e00b00418e716f987mr21186381edb.74.1648823889431; Fri, 01 Apr 2022 07:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648823889; cv=none; d=google.com; s=arc-20160816; b=zxEb/Q55DvqS4dKaKQjb6sY6hsoqAOAqSpNyu8fJ661cPPDyXZFnSdzHvy/ScizK8N 0eiljXiMLbdKsaQrfcdcCBox+YYwWbefdftypS85/ehYIncOo81CZkv8QmlcTdFqeKVQ aNYDYrYLIhT7A36GZFmdJrnEHkNS5dRVw63Tqnu//GhTUnfK4EVlwBKnAgnA4BBsWpu4 q6iJxvpnEh0zhlBPCTyk07YC6P6FZUoRZIx7aXqYjFTxD4mBGRr2COlOeZ8znUk/hPqY qQCJlvltHbvzhp33H74hxhaVtxuklLflIuEVGejz68YZ+Ms/rpHGT0QbKllQ4p952LA0 CIqg== 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=Xkr0PQO//o59RSxUJyyli+qBLYdHF3Dtr2QvlIoMNhs=; b=Hj/5qzac7a9URdigC7bXlLP4di1Mm4bwtP7Czx/g/3yo9c6ubH31AMK9YwNhoA6BN0 4kWhE876WlIkS4uJ8Ox1sP69VMbu6cZZAbOarmluD29P0CnevgCwkAcAshwUCYIo5HmM srFbSahKGPsEvrZbfklsRZKpUf/n208pDHxA0TyjuQYJqgUA8NZ08dKtMC+V1PDU9cPk okKITjWxPOFwD9t2Y3NcHcS14EKp4OZvTDWZcSDb6JmgvZxxw2wDCvebloHbvJihCiBN QxR6kfHuXVGa6UMIbhfN++U2p0qE2prMV++/F0PSowr3U2wgJEUUx0FcDn85SzUempzA PhaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g5npxspD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 30-20020a508e5e000000b00418c2b5beeasi1497390edx.460.2022.04.01.07.37.43; Fri, 01 Apr 2022 07:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g5npxspD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242109AbiCaV6v (ORCPT + 99 others); Thu, 31 Mar 2022 17:58:51 -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-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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; } -- 2.25.1