Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1048062ioo; Thu, 26 May 2022 23:37:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkt6KQFLaGZcd8xzktHkuBkKtHlcIWTAkwgqNCPMvR5VIX0HnOkpVRPbjHwz5yN45gSkV2 X-Received: by 2002:a17:902:ccc9:b0:15b:c265:b7a0 with SMTP id z9-20020a170902ccc900b0015bc265b7a0mr41030590ple.107.1653633457607; Thu, 26 May 2022 23:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653633457; cv=none; d=google.com; s=arc-20160816; b=vP+msOnNGw7xVcv+S9YEtNAeL3ip8zsRH7DA/QGkNY8Qrl2QX723xfS/K9Kb8gAuVP RuAQ1VQdO6nq9tI/xOoP4un22o0VFVX6jSBfp5dVwhHXHlZEAoxEz6brsW62e7nMJG3n C7TkZGYdqy299CaA/AcN7Y7FwkzBqLYzbB4A2LLLOZWqrj/jx94euQ5SLvyILgT/COd4 76coRsf/xL20w+X+LvhZaRapOwIaMjnrh2IOFQ1zzonTN8qGF39ejJSR1J4dAkoOnxoV LrB4V1KiC5fOOYY6zPbfAygwWbnkuqjWosavEBWIl5O3JXu3ZNIWVrgLmIPRZDJFQbL5 qSWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=qeYoBwClMquOdM4mrLC20XcvsQqVIaRivM3jxGFd6y4=; b=OWxTf7aBOklLycICy1n+IHbhsgoLgNdSpJMcHqwdxOPU/23+9d/XiWmW8C+UI5iKUM IdivaNPbI3OTkaEB085zaZMbhSkfU+kcbVHkWTmzKUAcHQ4YgIelsIiHjld3bZympnTG SOH/Ga9Bfl1rOqM6gwK38L6z0GtKWRJE3BziOBStX7INEBgfY8LIfcCU/zoXNkd+2Ii4 EUP3XMsW+50ebyiO+7p4IM1BWSCeaOQH9GNoM5mh9VI/8vaU7y23RAatppGmZt0yMYQ9 4H1XKnK4C2Vd9XZAUl2AggeqFBatIZMbh2XU6amCQLZTgMZhm5HLgxmKERoGrAnwqmUV qQhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UJ9nGADo; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d16-20020a170903231000b001620da7e3bfsi5320429plh.185.2022.05.26.23.37.12; Thu, 26 May 2022 23:37:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@redhat.com header.s=mimecast20190719 header.b=UJ9nGADo; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232903AbiEZUkp (ORCPT + 99 others); Thu, 26 May 2022 16:40:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231861AbiEZUkn (ORCPT ); Thu, 26 May 2022 16:40:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F26B8E15FF for ; Thu, 26 May 2022 13:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653597642; 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=qeYoBwClMquOdM4mrLC20XcvsQqVIaRivM3jxGFd6y4=; b=UJ9nGADox2ryLRzjbzy6zXGN5TSRcfz0/zctEWLDmgNxjF7ipVOvWxyvRsbwEvNiEPIgFl dr2RYpg4L8L7hNDvv3PfJYykD0CQy5jqy3ndLlmEG+Zu22oCEkAx+vAPjEbmqyXqDp9ppb md1IASkoJbnLdl6y6JSEIIYIGummVBc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-112-mc-1D6SBM96eFkb1G_VMfw-1; Thu, 26 May 2022 16:40:40 -0400 X-MC-Unique: mc-1D6SBM96eFkb1G_VMfw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A2A5D185A7A4; Thu, 26 May 2022 20:40:39 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31DDF1121315; Thu, 26 May 2022 20:40:39 +0000 (UTC) From: Jeff Moyer To: Frederick Lawler Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-security-module@vger.kernel.org, netdev@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, serge@hallyn.com, amir73il@gmail.com, kernel-team@cloudflare.com Subject: Re: [PATCH v2] cred: Propagate security_prepare_creds() error code References: <20220525183703.466936-1-fred@cloudflare.com> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Thu, 26 May 2022 16:43:44 -0400 In-Reply-To: <20220525183703.466936-1-fred@cloudflare.com> (Frederick Lawler's message of "Wed, 25 May 2022 13:37:03 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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-nfs@vger.kernel.org Frederick Lawler writes: > While experimenting with the security_prepare_creds() LSM hook, we > noticed that our EPERM error code was not propagated up the callstack. > Instead ENOMEM is always returned. As a result, some tools may send a > confusing error message to the user: > > $ unshare -rU > unshare: unshare failed: Cannot allocate memory > > A user would think that the system didn't have enough memory, when > instead the action was denied. > > This problem occurs because prepare_creds() and prepare_kernel_cred() > return NULL when security_prepare_creds() returns an error code. Later, > functions calling prepare_creds() and prepare_kernel_cred() return > ENOMEM because they assume that a NULL meant there was no memory > allocated. > > Fix this by propagating an error code from security_prepare_creds() up > the callstack. > > Signed-off-by: Frederick Lawler The fs/aio.c part looks ok to me. We should probably also update the man page for io_submit, though, to document the conditions under which EPERM can be returned. Acked-by: Jeff Moyer