From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D045C433EF for ; Thu, 26 May 2022 20:40:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D69138D0003; Thu, 26 May 2022 16:40:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D14858D0002; Thu, 26 May 2022 16:40:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDDB88D0003; Thu, 26 May 2022 16:40:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AF13E8D0002 for ; Thu, 26 May 2022 16:40:45 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 890B9805C7 for ; Thu, 26 May 2022 20:40:45 +0000 (UTC) X-FDA: 79509062850.06.081A452 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 5D576180053 for ; Thu, 26 May 2022 20:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653597644; 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=bqwbeML4mZmFzeeIuoGorMEqvHgWf7Az569VC9yVv52c0rhacUNi4INiEfNtYA3IxnJXan PZAMPtsRYdVf124SrvDYnKj7plgEKwNv07FcLknspHPE/C+LwyhitWpNnBsgXwRTYYoFpY v0lwlP7Om9nvyuxWiuVxCkGJhSRmS0Q= 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 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bqwbeML4; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf16.hostedemail.com: domain of jmoyer@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=jmoyer@redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5D576180053 X-Stat-Signature: jst5oqg9ta88ixfcjnqd7bqpjjsu664d X-HE-Tag: 1653597630-953732 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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