Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2208928rdf; Mon, 6 Nov 2023 07:41:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYguewrhO2XUe9Qxb/citYaxpkb0aC5VPZidhxDstkKFWhdHNB/JBwbNF++sC6JPPt4Cyz X-Received: by 2002:a17:902:f689:b0:1cc:6597:f421 with SMTP id l9-20020a170902f68900b001cc6597f421mr23847536plg.48.1699285290708; Mon, 06 Nov 2023 07:41:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699285290; cv=pass; d=google.com; s=arc-20160816; b=bX7u5kEMRNCMnK2oh8ywCMXsW3GYuPJ8ALxwstFq9e3C7BHw3MMcYSPmh7mmbi/q0Q XIoYhwwvC1qrUFjQLEDd7oar33FuiuhuH1WCY/ZLUnGGtqwWx8oA2xgatbTXIDwAbGKd qpRTGsrXB6hx/kfaac+HZDrhaFc62SKa1xR7JQzqTntdWLTiPGngG2Xz9B//N3FDVBMr uRwcGgaeZPyXaRE6ryhBkPMYm1R4DU+pu+mqb7f+AvE8ZfybrSL0B23WRhQ7reeDMYhe ZQy7FJANfMpEK5T/1C3ARTDC2a6xKrSdYkb+LhBmGN2eCm0drO1XmXJiSbKsBAOhaSt8 Yp0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:date:references:in-reply-to:subject :cc:to:from:dkim-signature:message-id; bh=91z7ELyQh9QsVWjhG+Jw0Nh7GkaLuv75onmOXjXEpqs=; fh=7rG5O1wvwNISDZTn3XRzTyLGVKqSw0sIU8x6/gmIRBM=; b=YIik/Kt5etfZtdakYTN8RPzU0y0ih21c3yMBCoVjvzCJInyuc74Iz6FJ/ngKRA8XGz xTPPhHmUmL8iOj+7wpFvuwKGtHxXLZmamog50SapctS5sOhKv8yRiLm6X08ruLTvgfJ+ NIaz3bId8d/mXgcmvbxSb0/MevaIhLdvrBr+umk0NrYYA/UXkIZNlr4/trHSryn1UORt 9fFPVrUI6uvVKCDt3BbBcMBv9DgKk93gAwiLqsfPvhHqltURnnp/kd54MpA5svrTmBFP iI2VokmFQQV5kOjn86pVIpGCKYuWqTPQOimyyaR++cR67WJFLl+x6N/p8lYhh8r2Nzqs lQVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@manguebit.com header.s=dkim header.b=IrOI4ZzX; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manguebit.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b10-20020a170902bd4a00b001cc38a6cb77si7893135plx.204.2023.11.06.07.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 07:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@manguebit.com header.s=dkim header.b=IrOI4ZzX; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manguebit.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id AF92F80A87F9; Mon, 6 Nov 2023 07:41:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbjKFPlN (ORCPT + 99 others); Mon, 6 Nov 2023 10:41:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231750AbjKFPlM (ORCPT ); Mon, 6 Nov 2023 10:41:12 -0500 Received: from mx.manguebit.com (mx.manguebit.com [167.235.159.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A15B10A; Mon, 6 Nov 2023 07:41:08 -0800 (PST) Message-ID: <919fa20e0951f962944b1f5c337a5911.pc@manguebit.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1699285266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=91z7ELyQh9QsVWjhG+Jw0Nh7GkaLuv75onmOXjXEpqs=; b=IrOI4ZzXo1pU7MQ8AaXfJo9qPuIR5a9leW+i2RydPEMWFpeXlihreM+UsZHxZ9SiGC0ctq I6iCqX3PH4h0Uygf6kXtKQ9lrN0vlxrPsnUE978UWCp3uLdyca4AnuP0SB1ByMwLsfeHbE Xc8wDx7tenHVxyYQCOCMCyw6MawOqYXLxAbr5XG8/XSZPuDz/PrXaG+cGSBsJoP+bdYWMO 3GBJgugK6xvCtaSNWyL/pNj4GXacItXKmqCS/On/UzLCvbkA5UoDOO/lpJalF3+m+2vg8S 8dfs1yC/y2R/6kKPW2lPtHmrHKozqxYUw+j3Jk8M17psjierGAkTr6MODLcrlw== ARC-Seal: i=1; s=dkim; d=manguebit.com; t=1699285266; a=rsa-sha256; cv=none; b=rb5yJBo0+t2qoQ8Wt0xey1Y3HCSlFWJyNay4GFixF3FoE2EqC8qVHOrid2kvoyacFGr9t/ SpTkp2gmpVwyOijrn7h68cpwO7vTKBqrXpqA8E+RFoDi+l84qMLWPL0j4A1d+Bp2vMPfMO 3+FhxZ+HtQ3ePRJF1K4+7F6/Sthsx2xUPV1oqUOszSi6l1RcLOTBeN6Rr66xgClO6GhA59 Smth8mRpO9sJhcji8ohpdaL78Ix5YncBKpMFqS2u0mKlOxk6cm00KiCRPY1enZIDDDI3cJ zQ+fyIr4ONXKQWmEkjbYEq9TPCs309LC6eGyKhVSaMVtJv7mjwdWN4jJ85YVwg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pc@manguebit.com smtp.mailfrom=pc@manguebit.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=manguebit.com; s=dkim; t=1699285266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=91z7ELyQh9QsVWjhG+Jw0Nh7GkaLuv75onmOXjXEpqs=; b=sFnJj1JXUZOZ+TmfIXD/4uWQy6/5NTw9EgDiVKlRmWmfqg3ZfIjX3gEtCQTDL4CWanpTy6 /wo/6DiK42PE7oLN3zA8z+EjTZxsewI5cwkDsfDc75j22IaIQtO9shPYf18utob3MwVPSX +zmhTRkkFgvxwTcYX2k5qmCyHTnZaWMNzLLewckxJabsHeRPryDFAtx/KCE6mw7EqR2ksg W69TaPeh0NtfTQl48px4XVUve8n5H/YenbEWyEr940RDIVi9QP0iWOhwdtvHe6TgSwcbqA qn0o6zlUX4jlBnu+sul/7Ypc1MHqs+b13dAYLOURCT4muTxjlT3UCFol9qw6ZQ== From: Paulo Alcantara To: David Howells , Damian Tometzki Cc: dhowells@redhat.com, Eric Biggers , Steve French , John Sanpe , CIFS , Namjae Jeon , LKML Subject: Re: [PATCH] cifs: Fix encryption of cleared, but unset rq_iter data buffers In-Reply-To: <2610852.1699281611@warthog.procyon.org.uk> References: <20231022183917.1013135-1-sanpeqf@gmail.com> <20231105193601.GB91123@sol.localdomain> <20231105201516.GC91123@sol.localdomain> <2610852.1699281611@warthog.procyon.org.uk> Date: Mon, 06 Nov 2023 12:41:01 -0300 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 07:41:27 -0800 (PST) David Howells writes: > cifs: Fix encryption of cleared, but unset rq_iter data buffers > > Each smb_rqst struct contains two things: an array of kvecs (rq_iov) that > contains the protocol data for an RPC op and an iterator (rq_iter) that > contains the data payload of an RPC op. When an smb_rqst is allocated > rq_iter is it always cleared, but we don't set it up unless we're going to > use it. > > The functions that determines the size of the ciphertext buffer that will > be needed to encrypt a request, cifs_get_num_sgs(), assumes that rq_iter is > always initialised - and employs user_backed_iter() to check that the > iterator isn't user-backed. This used to incidentally work, because > ->user_backed was set to false because the iterator has never been > initialised, but with commit f1b4cb650b9a0eeba206d8f069fcdc532bfbcd74[1] > which changes user_backed_iter() to determine this based on the iterator > type insted, a warning is now emitted: > > WARNING: CPU: 7 PID: 4584 at fs/smb/client/cifsglob.h:2165 smb2_get_aead_req+0x3fc/0x420 [cifs] > ... > RIP: 0010:smb2_get_aead_req+0x3fc/0x420 [cifs] > ... > crypt_message+0x33e/0x550 [cifs] > smb3_init_transform_rq+0x27d/0x3f0 [cifs] > smb_send_rqst+0xc7/0x160 [cifs] > compound_send_recv+0x3ca/0x9f0 [cifs] > cifs_send_recv+0x25/0x30 [cifs] > SMB2_tcon+0x38a/0x820 [cifs] > cifs_get_smb_ses+0x69c/0xee0 [cifs] > cifs_mount_get_session+0x76/0x1d0 [cifs] > dfs_mount_share+0x74/0x9d0 [cifs] > cifs_mount+0x6e/0x2e0 [cifs] > cifs_smb3_do_mount+0x143/0x300 [cifs] > smb3_get_tree+0x15e/0x290 [cifs] > vfs_get_tree+0x2d/0xe0 > do_new_mount+0x124/0x340 > __se_sys_mount+0x143/0x1a0 > > The problem is that rq_iter was never set, so the type is 0 (ie. ITER_UBUF) > which causes user_backed_iter() to return true. The code doesn't > malfunction because it checks the size of the iterator - which is 0. > > Fix cifs_get_num_sgs() to ignore rq_iter if its count is 0, thereby > bypassing the warnings. > > It might be better to explicitly initialise rq_iter to a zero-length > ITER_BVEC, say, as it can always be reinitialised later. Agreed. We could probably set those in ->init_transform_rq(). > Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list") > Reported-by: Damian Tometzki > Link: https://lore.kernel.org/r/ZUfQo47uo0p2ZsYg@fedora.fritz.box/ > Signed-off-by: David Howells > cc: Steve French > cc: Shyam Prasad N > cc: Rohith Surabattula > cc: Paulo Alcantara > cc: Namjae Jeon > cc: Tom Talpey > cc: Jeff Layton > cc: Eric Biggers > cc: linux-cifs@vger.kernel.org > cc: linux-fsdevel@vger.kernel.org > Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f1b4cb650b9a0eeba206d8f069fcdc532bfbcd74 [1] > --- > fs/smb/client/cifsglob.h | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) FWIW, the patch fixes mounts of shares with encryption enabled. Reviewed-by: Paulo Alcantara (SUSE)