Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp691645pxb; Wed, 11 Nov 2020 13:53:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgQ/rCv89upPA3Y07465VDAIE0qCGfJYBmuP16h0EFH+O+Qh5GbxNYbpaz68n3Mne5bh5S X-Received: by 2002:a05:6402:3131:: with SMTP id dd17mr1793525edb.58.1605131589267; Wed, 11 Nov 2020 13:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605131589; cv=none; d=google.com; s=arc-20160816; b=gRNaJBgJJg3sD2WvJOATcQr8U+ePyoJJV3d/bWC9UrQ3ajvqcV50VFkX5ArygyeXLo kyuzzgHpadgM/48263IH4Dzp9C/cnrR2wSaiK5POAPgvKy8CVMCe29vX1HM2bMmLXAF0 uW4b8I2Fnu7/6ReYE/I04qDYElnrNA2GXjFQ2LBwSWYcbEYWFBQS2+pX5L8gkLHiceER 8z0Ughbi0oFoDHn8v0bginuIl2pK0fIwdgW2BluISczGZu4iDiP0oQDUgIGmKKHbt/sN bG6jKGX2tQvnIhv6dM/0ag9XEzULOTKrloalHqYDLj5QUVZlolcRhr9PdwudjdDY6Cpc PLww== 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=g/7JfACUirq9jWA9M9E2xaK3d3HlBQ8p/9KQdHk+5e3M1BCm67ZmCohrfbfjSRn/z6 3ldSwJV7cRwPRSFI50D++dltMJoVV0zVMBIIMfN0EgQGfPrYpguMCdgyEqQNTXHIxPkx fWuAEorLobtDmpxgyHCiMOyJZJHmsGWOJtiYa+mfLl7jdsiQLMyEnh7FzeOkmnYAODgX Vl4J8HLxq14hgHO+NFkgitDxLMO4uPtMw/0eW1Yp8dOkWJ9JeXVzpwZRYv9vZCXxQloZ tRDmr78m6jQFwJi2C+e8leoOoq/jt4EAyo8GN75pevso0cD82lzEvVHyJaSIJvDVNIXG u1Mg== 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 k5si2169169ejk.655.2020.11.11.13.52.36; Wed, 11 Nov 2020 13:53:09 -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 S1726419AbgKKVwc (ORCPT + 99 others); Wed, 11 Nov 2020 16:52:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgKKVwc (ORCPT ); Wed, 11 Nov 2020 16:52:32 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3233C0613D1; Wed, 11 Nov 2020 13:52:31 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id E32E01F45DC8 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 RFC v2 1/8] watch_queue: Make watch_sizeof() check record size Date: Wed, 11 Nov 2020 16:52:06 -0500 Message-Id: <20201111215213.4152354-2-krisman@collabora.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201111215213.4152354-1-krisman@collabora.com> References: <20201111215213.4152354-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