Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1668125ybj; Fri, 20 Sep 2019 14:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqztq7R/yNH0Bci/dUr1nfKKrP4iSsaVwAmOWUXrTuXyL8r5W1VTXx5o5yHMHr+zdIFNt2u9 X-Received: by 2002:aa7:d750:: with SMTP id a16mr24286551eds.27.1569014900783; Fri, 20 Sep 2019 14:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569014900; cv=none; d=google.com; s=arc-20160816; b=GM430tRNr67ds9c8USdhH0t3gz2ixwvfj8sSGRTFyMA8WWs6PwbeU/a1p0M4k1YTE5 VI75D8WW2vVgh62nOZJrNBzOkQBWBcqYYohAmaWwLlhlfsypDNPglC1WvAu97QMCjCJT S56anUhM/+3U/Lkn48+K+7zhKCVJIWtVq9zsF/XetF1+ey0AnbarlPDBQS8Z/0AIp1Zm G/lkB5rLR/FYBT5udr8uviHtDiCEcMnq4FhZsxV4BqQ9FJlYGbiEzcsoB33PuLXEYbjZ 9va7ErNKaA74dZ9JGTJIcST9CJrml/N9AfYjjekOXEK2dvmxCm/bUjw236mIcoTJWBfs Z41Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=m6ayjb5Y1w+paqBDeMRBFKWOnuXQJVkXbMguPcmxhXw=; b=yi4JfFLjOj6qVKcnc6b6X/zlKWYEsZXmMgF4p4pFhRzyNLs4wK8KtxmuV5XgGvLo/p gai8Q3CxdI3+H86pYUY7In+NPgTkQ6cSL8KVeu10+ou0g10wwYihgNagnbk/OeNL6ZG8 L0PEnPayIi/X4Wj6ngvpHuhSZi7F1ZIm3MTPuYKIA3NagXxw95ZJk5oSc5h847d6B0Ve j9ig+h4PwgUmwI+YkiQclhOQZ3Bz1GdZwPEoEhUwRrFeRwMVl4jPtZWBLOdYth++U+JK q3kFevug0F8T8Dg5G32zNB64Td1vSjrtZyvcEyAxiUYzyMib9TQfrUMV6x5OxaTAyjki mdYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYh9FfAV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si2230861edb.56.2019.09.20.14.27.57; Fri, 20 Sep 2019 14:28:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYh9FfAV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2393673AbfITAMK (ORCPT + 99 others); Thu, 19 Sep 2019 20:12:10 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40793 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390329AbfITAMJ (ORCPT ); Thu, 19 Sep 2019 20:12:09 -0400 Received: by mail-lf1-f66.google.com with SMTP id d17so3672776lfa.7; Thu, 19 Sep 2019 17:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=m6ayjb5Y1w+paqBDeMRBFKWOnuXQJVkXbMguPcmxhXw=; b=oYh9FfAVWj1Q8HXOkLBpoLgbYmc6y9vM35bODz9VsXxVkIqyCAl85OpIuDt09tBcqE AWudGE24UZBcjqPVCrBy2tKKmb3RryVREfzMdZxIRDdIQan2GkrIJTODF7kHAjdEIZ1x SKkdkfW/qRQhyhH2ENa8uH3G9psyoAqgnI6xS9S90quhsAIpD0QlDe4BZ6eTopdmEQt1 7E6JqzHPY3ZATPrbH3UdS+S/Ygpu3KU1v472TwQCC9NT4ii/n3QHTV+GOhzS4OHA5/3j n01CjNRSmbAQT+dO8Ylzz8P2erKOT5mHGXjXXrekFDnEPL2PqXykqql5I/y1mpD6yicA KkBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=m6ayjb5Y1w+paqBDeMRBFKWOnuXQJVkXbMguPcmxhXw=; b=VXQt1wqZKcMl44uWSDhi8JXTs7Md9S2e16DztYuI/0Hh7Q6XkF3g7YdEqn5X6PpxDM HM9EFBJshuhK/auf1k4+zdzSbmYkgm9Vi+iDa4gQM4P0CX7ZZAYpgaqxXQGhRwhqDPQn LBcVNjwDwrRkGJXwv4rEfaviVbnGNSZuq+ufGZ1C7POjxN0WOl1RtFeZ3wwWK4itqfPJ 1Q+jfjcJ75fmeafyFCvnxVFpWIhtk+v1+KDqzeMcMyXv5BNpHyQ42hmPVTo/gBuxe0P+ K15GcpeMuKP2vEiMdKsD7b2o5dppHWLDSaC2sFgTcOD9bXkMm9oh6UZfqryJCjz/bqyP mqdQ== X-Gm-Message-State: APjAAAU4ZWsRAb3Qe5fbh3rAENAWS44dIco0Jcyls17Zzw2hOM1ci6K1 c9yzkY4j56IMfjlqVrpD82KSIqhcfTTgyWqA1Q== X-Received: by 2002:a19:8a0b:: with SMTP id m11mr6409704lfd.4.1568938326291; Thu, 19 Sep 2019 17:12:06 -0700 (PDT) MIME-Version: 1.0 References: <20190829050237.GA5161@jagdpanzerIV> In-Reply-To: <20190829050237.GA5161@jagdpanzerIV> From: Pavel Shilovsky Date: Thu, 19 Sep 2019 17:11:54 -0700 Message-ID: Subject: Re: build_path_from_dentry_optional_prefix() may schedule from invalid context To: Sergey Senozhatsky Cc: Steve French , Ronnie Sahlberg , linux-cifs , Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =D1=81=D1=80, 28 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3. =D0=B2 22:02, Sergey Seno= zhatsky : > > Hello, > > Looking at commit "cifs: create a helper to find a writeable handle > by path name": > > ->open_file_lock scope is atomic context, while build_path_from_dentry() > can schedule - kmalloc(GFP_KERNEL) > > spin_lock(&tcon->open_file_lock); > list_for_each(tmp, &tcon->openFileList) { > cfile =3D list_entry(tmp, struct cifsFileInfo, > tlist); > full_path =3D build_path_from_dentry(cfile->dentry); > if (full_path =3D=3D NULL) { > spin_unlock(&tcon->open_file_lock); > return -ENOMEM; > } > if (strcmp(full_path, name)) { > kfree(full_path); > continue; > } > kfree(full_path); > > cinode =3D CIFS_I(d_inode(cfile->dentry)); > spin_unlock(&tcon->open_file_lock); > return cifs_get_writable_file(cinode, 0, ret_file); > } > > spin_unlock(&tcon->open_file_lock); > > Additionally, kfree() can (and should) be done outside of > ->open_file_lock scope. > > -ss Good catch. I think we should have another version of build_path_from_dentry() which takes pre-allocated (probably on stack) full_path as an argument. This would allow us to avoid allocations under the spin lock. -- Best regards, Pavel Shilovsky