From patchwork Mon Mar 22 16:02:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406159 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp1347084ejm; Mon, 22 Mar 2021 09:03:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHZis5RH06GCYolF8Lf5oB8mfRVCSwXczXlERxnSuoJK4GUNFYeSJDMJ58EqWNFuLDlBnV X-Received: by 2002:a17:902:b781:b029:e4:545d:77 with SMTP id e1-20020a170902b781b02900e4545d0077mr443164pls.59.1616429039698; Mon, 22 Mar 2021 09:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616429039; cv=none; d=google.com; s=arc-20160816; b=RZkuR4QDbwRtFjqnxHtWdCtTWoDKZCPGnhYXI9WjweIi6q4q3USdwt7QJm+SPkh3sx 02fHo27O9P8fUIfO4SgvTPLoMW4J+1DWQNoUZHRVlMbBBpFZTKMKIQRVANHYKqO9gguS tJ1tgrst0a3PPrWmOQyQ7Xe2c0O2WGSjLR1WqxGvhyAfl5L2yKQx/OEwLeOVDx5Jxuak Y7pql1CZCm7ds2PEF+KRjRYMQ8Hfria4ANF/uVkQRg8sMeMwlAt31EYk6knKtdfInspJ jHhkaR1e7AIxuKAJvsDe2XfBxCWEbhA4YPt7SOLcWZMi9CIY8DOmCe3zDh3xLj+uLGUQ Jz0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to; bh=E73QMOZ8viGNiDYJyLFjn6iMy3804zOGrz/MDNrrLkU=; b=HSXvZdxIk2SoUK7vs9H+wv2XiJEx7qVr4OVjcO2qVrw7Doah9q9SQ5W3Pf5hG7mAiX SYgQ8qRBqtQ2BCvB+m6maBEpAFkkJ5a4KT/WgQmVbc+VwLXY6Wkqum7DFBpvlQrsD8I1 krOCU+cRIqkcsOIktGOlQK68QJ5P/W/goOU2RJjHlXHc9w4/YEuK9ckF9shGE7ZED+u5 pcyDdfVfq/Isl8EV6KGY8AUsTJQmOu47DpZs9noI52cGfbeHwCdUOGfZ6n/CLrqMNXFy 8AKNyUkZdqvJ+uNv9A5HQITfa0qIcBzLwAhNBXDglQlkDgdy4olW/lbl4yRRFk+092bn HuYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=DnY2VvcI; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id a15si17372559pgw.241.2021.03.22.09.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 09:03:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=DnY2VvcI; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7808189CA2; Mon, 22 Mar 2021 16:03:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8861789CA2; Mon, 22 Mar 2021 16:03:56 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4428761998; Mon, 22 Mar 2021 16:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616429036; bh=yFqEt0Vza9xx1ZEH6vpmadF/s9WD+9cr+PvfYFx1jTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnY2VvcIHWNR00CmYsS8o9sdpXW8IfqlUTn3pfDogyHxX/SIITlr8SG6GxkT3eSRZ a7K8jLXsPna4Mm190+MpWcuBICb/n+i193Sgx5UJVnr/NQaks4zNGBOOkdJN7kk+Zx IrtL2gHR1/fBjD9NvgLiYwkQqQ/EKWhfodExGrNMHcxDZouSH1dybJZC/EbBnOcXm9 XQLG8dt1bjMaDOofLpAx013Fhy9k111G7DuVnc/32l3avRksgUDzsBf0x12znYeUYk RAdBhG+/y/EhxEsBwjpyhm77vbHfFV6Wbj7ETM5qbIRB/4/X2e34tKnfe8hgDnqlGY gToo1OwJ8lpqg== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Martin Sebor , Serge Hallyn , James Morris Subject: [PATCH 03/11] security: commoncap: fix -Wstringop-overread warning Date: Mon, 22 Mar 2021 17:02:41 +0100 Message-Id: <20210322160253.4032422-4-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210322160253.4032422-1-arnd@kernel.org> References: <20210322160253.4032422-1-arnd@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, Christian Brauner , linux-scsi@vger.kernel.org, x86@kernel.org, James Smart , tboot-devel@lists.sourceforge.net, Kalle Valo , ath11k@lists.infradead.org, Miklos Szeredi , Kees Cook , Arnd Bergmann , "James E.J. Bottomley" , Ning Sun , Anders Larsen , cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-security-module@vger.kernel.org, "Eric W. Biederman" , Tejun Heo , Simon Kelley , intel-gfx@lists.freedesktop.org, Tycho Andersen Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann gcc-11 introdces a harmless warning for cap_inode_getsecurity: security/commoncap.c: In function ‘cap_inode_getsecurity’: security/commoncap.c:440:33: error: ‘memcpy’ reading 16 bytes from a region of size 0 [-Werror=stringop-overread] 440 | memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The problem here is that tmpbuf is initialized to NULL, so gcc assumes it is not accessible unless it gets set by vfs_getxattr_alloc(). This is a legitimate warning as far as I can tell, but the code is correct since it correctly handles the error when that function fails. Add a separate NULL check to tell gcc about it as well. Signed-off-by: Arnd Bergmann --- security/commoncap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/commoncap.c b/security/commoncap.c index 28f4d25480df..9a36ed6dd737 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -400,7 +400,7 @@ int cap_inode_getsecurity(struct user_namespace *mnt_userns, &tmpbuf, size, GFP_NOFS); dput(dentry); - if (ret < 0) + if (ret < 0 || !tmpbuf) return ret; fs_ns = inode->i_sb->s_user_ns;