From patchwork Fri Jul 24 13:11:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11683217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91E9B13A4 for ; Fri, 24 Jul 2020 13:11:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7973A20714 for ; Fri, 24 Jul 2020 13:11:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DyKi6ZYV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726899AbgGXNLk (ORCPT ); Fri, 24 Jul 2020 09:11:40 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59994 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726235AbgGXNLk (ORCPT ); Fri, 24 Jul 2020 09:11:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595596298; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ylt84/QjuXGByWDOUhtjvYR5Fe+CedjDeH1XsQdkc6w=; b=DyKi6ZYVFkMwphn0xHqmFn704FFqBhDR7UBQbdUEYF1BVyqzEPRXWLCwQJ7iyHiuQTa2dT CHg1sZ7MQ3CbK+DCCXoEHSip8ky3s+BBfgQeRsYgCjsacqxi4dezwqayRCBCveG3BbYnaX G78FgFjPeI5uciEyfqBLkEmXeD+cs+4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-8WoYLrGpMVK7fV2fTsqdqQ-1; Fri, 24 Jul 2020 09:11:37 -0400 X-MC-Unique: 8WoYLrGpMVK7fV2fTsqdqQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E16F100CCC5; Fri, 24 Jul 2020 13:11:35 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-112-32.rdu2.redhat.com [10.10.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F9795D9E8; Fri, 24 Jul 2020 13:11:32 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/4] watch_queue: Make watch_sizeof() check record size From: David Howells To: viro@zeniv.linux.org.uk Cc: Miklos Szeredi , dhowells@redhat.com, torvalds@linux-foundation.org, casey@schaufler-ca.com, sds@tycho.nsa.gov, nicolas.dichtel@6wind.com, raven@themaw.net, christian@brauner.io, jlayton@redhat.com, kzak@redhat.com, mszeredi@redhat.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 24 Jul 2020 14:11:31 +0100 Message-ID: <159559629177.2141315.10412134789878021738.stgit@warthog.procyon.org.uk> In-Reply-To: <159559628247.2141315.2107013106060144287.stgit@warthog.procyon.org.uk> References: <159559628247.2141315.2107013106060144287.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 --- 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 5e08db2adc31..38e04c7a7951 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; \ + }) #endif