Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp117681pxv; Wed, 30 Jun 2021 01:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEMt4JwLLJZw7oPEWHo1qFE38EqIwEs7PrqSZnoD5PMC8Ukclce8qAbuF2mOv5s4voKDHm X-Received: by 2002:a5d:9f07:: with SMTP id q7mr6660180iot.169.1625040718430; Wed, 30 Jun 2021 01:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625040718; cv=none; d=google.com; s=arc-20160816; b=00raWBOi5D2LADQIL2HRhhNIV6ljHixfkEM5p/rAR1xH+XR+cyOxjP3ppKKAMygmU8 i1XwwoTpxVZh7tRHSumcjkuUl6QM1xImXpOmPOqTsddOjE1cshc9neN1kVmgO+PRLQcO MCkDS92LKY6uqZ/ogsxCBuR8N53Tb/0EnuVZdTPx3ru3aqRGT+KeVJuKuiIxWx8mqsS0 rDcKgvrLgyLwy9svMSLCnU/Rn71DT0n4qzlgkl98A6tKquAFoWE5r+INQZWjyYtXmkUQ 3j3qhkOWs44cIupsmOmj+gOAUGyfV7cjDvZQz52QTZ+l8PykMuA97tLbg675oQWCZqtD dw7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=lVYDSlk0SPv+y3wa9F+yMFj3rfhek5OFZ/MAOe/Ye+k=; b=PtcNfRTNJZXv52BJtvail86mQ6JDr80f3CgAy/RadUmHPrvBssvjAbetdOWkn6KtL1 QIYOdgwnl0gPnpuqhA76VndEpbP4ie042vIgMGGY6Zb2E8HhasjreF2hwiwmiA31cfEn YxJgB7ISp2+veJpvduIF9cvi8S+wxdY9QLJE+Ijt/RS+jdWASFUqnK0DBeEwcyXmd4ug m0fZ1Yl7G2Kzs4LgnrU7jnND/QLrO++6hO2+YzbDJHljP9pJXTVGXrEtRCC376VYzHU7 DYFeWIn3JBjEG1pai3NwMgxECwveZwuMg5z10ke+D9vdE2QbBXISZoI2ZW/FWfNj4fcS n/Yw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si4754584ilq.26.2021.06.30.01.11.46; Wed, 30 Jun 2021 01:11:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233219AbhF3IMc (ORCPT + 99 others); Wed, 30 Jun 2021 04:12:32 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:51056 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232954AbhF3IMc (ORCPT ); Wed, 30 Jun 2021 04:12:32 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.92 #5 (Debian)) id 1lyVI6-0006Ui-RC; Wed, 30 Jun 2021 16:09:50 +0800 Received: from herbert by gondobar with local (Exim 4.92) (envelope-from ) id 1lyVHq-0006L3-N8; Wed, 30 Jun 2021 16:09:34 +0800 Date: Wed, 30 Jun 2021 16:09:34 +0800 From: Herbert Xu To: Ard Biesheuvel Cc: Dave Hansen , syzbot , Borislav Petkov , "H. Peter Anvin" , jpa@git.mail.kapsi.fi, kan.liang@linux.intel.com, Linux Kernel Mailing List , Andy Lutomirski , Ingo Molnar , syzkaller-bugs , Thomas Gleixner , X86 ML Subject: Re: [syzbot] BUG: sleeping function called from invalid context in __fdget_pos Message-ID: <20210630080934.GA24186@gondor.apana.org.au> References: <000000000000f3e94a05c5d8686f@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ard: On Wed, Jun 30, 2021 at 09:42:14AM +0200, Ard Biesheuvel wrote: > > > There's one suspect-looking site in xts_crypt(): > > > > > kernel_fpu_begin(); > > > > > > /* calculate first value of T */ > > > aesni_enc(aes_ctx(ctx->raw_tweak_ctx), walk.iv, walk.iv); > > > > > > while (walk.nbytes > 0) { > > > int nbytes = walk.nbytes; > > > > > > ... > > > > > > err = skcipher_walk_done(&walk, walk.nbytes - nbytes); > > > > > > kernel_fpu_end(); > > > > > > if (walk.nbytes > 0) > > > kernel_fpu_begin(); > > > } > > > > I wonder if a slab allocation failure could leave us with walk.nbytes==0. > > The code is actually the other way around: kernel_fpu_end() comes > before the call to skcipher_walk_done(). > > So IIUC, this code forces an allocation failure, and checks whether > the code deals with this gracefully, right? > > The skcipher walk API guarantees that walk.nbytes == 0 if an error is > returned, so the pairing of FPU begin/end looks correct to me. And > skcipher_walk_next() should not invoke anything that might sleep from > this particular context. > > Herbert, any ideas? xts_crypt looks buggy to me. In particular, if the second skcipher_walk_virt call (the one in the if clause) fails, then we will return without calling kernel_fpu_end. Another issue, we are not checking for errors on the first skcipher_walk_virt call, this may cause a double-free with the subsequent skcipher_walk_abort inside the if clause. With skcikpher_walk_virt, you must check for errors explicitly *unless* you use it in a loop construct which exits on !walk->nbytes. Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt