Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2811668pxu; Mon, 7 Dec 2020 16:56:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyz6kWLldIt1P0YPRSumNQntxUMwazLd22V36yz38nqHKkxdQfREcjnwq3k7dksFqh8Ps/0 X-Received: by 2002:a17:907:2122:: with SMTP id qo2mr19011764ejb.539.1607388996997; Mon, 07 Dec 2020 16:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607388996; cv=none; d=google.com; s=arc-20160816; b=sTjJP98XMj+5EMfMil9EdNmu9PcdX30hfYyizqrD6w4PACMDNXFQQUSmJBnLZsRbml QQxhpi4flhGwzOMSPrDhxk3j8lWOMCKEVO8D2Be21oy4Dy/XONjdN2nRwGxHerJ8us++ Fz0DFyEm7lgzIY5SnY3xVtJEaMS1n8redsJzuVi5iyoLoM53g0LpQDriENaSGLzrvQTs Yy7d0hZy6ORQqL+IqUi9+EZ+oflU/Olsq8noxZC224MlXrEvmLznTsq/1Uw4i+ZIYeuK KI09EAN9CqVjPZtAx9d6OqeOtotsm3fUopO9S95mV8qNCjN4jVP5eX95p2Ocs5EpDrWE aYDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6iAlIZqRQjcF2srOIR5m6F0sMcqPSnrgV0QHoB5yX0c=; b=wBtK3al/HYb8Il+QXn75giPdP5FZqxc18g/0cZ+Ky+CzxJKxbiTT5V/nEN7SO/7jEI B1roDIozYczIA81LGiNpecG8GxvNE0Y8aJNGDWPDFt2/impHjSvBZlkLjJXIn4Ar/XeE prtun42czS1z2xx7N/jXaurjbblzjAB2qratqtLGFcca9b3QH2Ln6M1sofFfaw2Hd2u8 HS7mo17QT+M50LeU3TM3EzKs+lD6zjLyjdNmnO3Y4iGqzgf42yIfAhYxIkPkQaSw2cwN heXi4a1XHl1CJWCBWXWegOkMadqic8NEGOgj2DQ+SrnMvWQ6KDRbvlSfBErOdsoiYXMT kfFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt5si7345356ejb.639.2020.12.07.16.56.14; Mon, 07 Dec 2020 16:56:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbgLHAcO (ORCPT + 99 others); Mon, 7 Dec 2020 19:32:14 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:56578 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbgLHAcO (ORCPT ); Mon, 7 Dec 2020 19:32:14 -0500 Received: from localhost (unknown [IPv6:2804:14c:132:242d::1001]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id BC57A1F44CFF; Tue, 8 Dec 2020 00:31:31 +0000 (GMT) From: Gabriel Krisman Bertazi To: dhowells@redhat.com Cc: viro@zeniv.linux.org.uk, tytso@mit.edu, khazhy@google.com, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Miklos Szeredi , Gabriel Krisman Bertazi Subject: [PATCH 1/8] watch_queue: Make watch_sizeof() check record size Date: Mon, 7 Dec 2020 21:31:10 -0300 Message-Id: <20201208003117.342047-2-krisman@collabora.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208003117.342047-1-krisman@collabora.com> References: <20201208003117.342047-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: David Howells Make watch_sizeof() give a build error if the size of the struct won't fit into the size field in the header. Reported-by: Miklos Szeredi Signed-off-by: David Howells [Rebase to 5.10] Signed-off-by: Gabriel Krisman Bertazi --- include/linux/watch_queue.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index c994d1b2cdba..f1086d12cd03 100644 --- a/include/linux/watch_queue.h +++ b/include/linux/watch_queue.h @@ -120,7 +120,12 @@ static inline void remove_watch_list(struct watch_list *wlist, u64 id) * watch_sizeof - Calculate the information part of the size of a watch record, * given the structure size. */ -#define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT) +#define watch_sizeof(STRUCT) \ + ({ \ + size_t max = WATCH_INFO_LENGTH >> WATCH_INFO_LENGTH__SHIFT; \ + BUILD_BUG_ON(sizeof(STRUCT) > max); \ + sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT; \ + }) #else static inline int watch_queue_init(struct pipe_inode_info *pipe) -- 2.29.2