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 F29FDC4332F for ; Fri, 2 Dec 2022 21:55:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73D476B0071; Fri, 2 Dec 2022 16:55:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EC396B0072; Fri, 2 Dec 2022 16:55:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58D1E6B0073; Fri, 2 Dec 2022 16:55:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 493266B0071 for ; Fri, 2 Dec 2022 16:55:38 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D437E1613D0 for ; Fri, 2 Dec 2022 21:55:37 +0000 (UTC) X-FDA: 80198723514.25.1E006AF Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf24.hostedemail.com (Postfix) with ESMTP id 5F87418000D for ; Fri, 2 Dec 2022 21:55:37 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=URC9xhK7; spf=pass (imf24.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.175 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670018137; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t/wakp1HXP8TMhCgpZ+F2SUDPBBbIjX7REGlztKJoc8=; b=RBL4Bzbc/BUlHLjllIx7PFjfgWRLuwV8NBKojHuwmDo8mmSD711cNaJ8H/S3nIF3U9Eufr ayePuV/IC53RQxuf7eWgvwewNLzsFKw0Rc8B+MlvFNeR8e+OPz9n8WJqLiepbhiSAoLp1q 3dI6mYJ5GGXOry5rWTknsD6bfS8VAP0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=URC9xhK7; spf=pass (imf24.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.175 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670018137; a=rsa-sha256; cv=none; b=whFl6TnVe3uZlq85Jt/6VJrjtfIGXRr0XUlLWEU2C5rmKM8PE14t57vto61R7no091LyIE 1VO5OCiIK5HImShlOUYWkf+WKuFrNw9/36a+qQi7HjFfLUbYYfrM9SqZqp3alIa3x3Strn ZF3KwMGsk8WDV3UQvSeBzLe/apqh4AU= Received: by mail-pg1-f175.google.com with SMTP id 62so5413966pgb.13 for ; Fri, 02 Dec 2022 13:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=t/wakp1HXP8TMhCgpZ+F2SUDPBBbIjX7REGlztKJoc8=; b=URC9xhK7FKnFKW8fyyyNwQXIgHH0vadxT/JEPEGuyThkxxUmSSKQHwuzHDxJWAqF9s Wbc2rol+II/v+G3Pk8zz//vEk6FTA1vwgJFm2+vvBSEQnyiJHrIFeWx4DEQWC7v42caI m6pu5bcn99GGLqDxvY+8goxri1YqH4b1pEV14= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=t/wakp1HXP8TMhCgpZ+F2SUDPBBbIjX7REGlztKJoc8=; b=X6X45ig5iiqdT72iqPSh0IUMM2SktVj4wu/cW1LQmcEY4lf+qFlHYxJD34oDKFxHM6 2Lw4i7XlAwzeeNGl1oNq5HOf6K1xjL2ww3PXWRJhtVysXhFfs5Pw7qLojFbaHkFOXHwh md1NrnUOHLOG+52MMoFHgooe0VbdYrzGDg+D0LbYwcbfRx8AhAmDnfGXnclgVC03H7FD xIRJ67f3IRMO9wiPKUZ1V0i9l7OwvZvlHq9PHdcAscBi7ei1MwCpT39PItZmHrXspucf RhXLqXUMSDCJlz22iw3fOAMKFg45PQPdjCckseBn0dPc/Kiqjxnj4aaYkLqj72FN3uPV q1cQ== X-Gm-Message-State: ANoB5plcSu1N7DV4nzFxxfVkGi72UuI//fh4AFsMjObazsbr/+E5wf+E 4ekSLImu88qlxjr5FQd//D8wYQ== X-Google-Smtp-Source: AA0mqf4idAsVzzBsnh5br+mYM/h6nKbQpq33CDvgMlmnMhaTye/RDJV7RzRjHysc7BnJYEf3yB36kw== X-Received: by 2002:a65:4c85:0:b0:46f:59bd:6125 with SMTP id m5-20020a654c85000000b0046f59bd6125mr64842218pgt.147.1670018136199; Fri, 02 Dec 2022 13:55:36 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a7-20020aa78e87000000b005764c8f8f07sm2130601pfr.84.2022.12.02.13.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 13:55:35 -0800 (PST) Date: Fri, 2 Dec 2022 13:55:34 -0800 From: Kees Cook To: Al Viro Cc: Liu Shixin , Eric Biederman , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] binfmt_misc: fix shift-out-of-bounds in check_special_flags Message-ID: <202212021352.BF39C94C@keescook> References: <20221102025123.1117184-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 5F87418000D X-Stat-Signature: 9hxrnp44o9gteeyqcau9agaxga4mp3xr X-Rspam-User: X-Spamd-Result: default: False [3.44 / 9.00]; SORBS_IRL_BL(3.00)[209.85.215.175:from]; BAYES_HAM(-1.16)[81.45%]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MID_RHS_NOT_FQDN(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; BAD_REP_POLICIES(0.10)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[chromium.org:+]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_FIVE(0.00)[6]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(0.00)[chromium.org:s=google]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Server: rspam08 X-HE-Tag: 1670018137-785183 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Nov 19, 2022 at 05:29:22AM +0000, Al Viro wrote: > On Wed, Nov 02, 2022 at 10:51:23AM +0800, Liu Shixin wrote: > > UBSAN reported a shift-out-of-bounds warning: > > > > left shift of 1 by 31 places cannot be represented in type 'int' > > Call Trace: > > > > __dump_stack lib/dump_stack.c:88 [inline] > > dump_stack_lvl+0x8d/0xcf lib/dump_stack.c:106 > > ubsan_epilogue+0xa/0x44 lib/ubsan.c:151 > > __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 lib/ubsan.c:322 > > check_special_flags fs/binfmt_misc.c:241 [inline] > > create_entry fs/binfmt_misc.c:456 [inline] > > bm_register_write+0x9d3/0xa20 fs/binfmt_misc.c:654 > > vfs_write+0x11e/0x580 fs/read_write.c:582 > > ksys_write+0xcf/0x120 fs/read_write.c:637 > > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > do_syscall_64+0x34/0x80 arch/x86/entry/common.c:80 > > entry_SYSCALL_64_after_hwframe+0x63/0xcd > > RIP: 0033:0x4194e1 > > > > Since the type of Node's flags is unsigned long, we should define these > > macros with same type too. > > We are limited to 32 bits anyway. More interesting question here is what's > the point of having those bits that high anyway? Hm, looks like it was designed to avoid the enum just before the defines: enum {Enabled, Magic}; #define MISC_FMT_PRESERVE_ARGV0 (1 << 31) #define MISC_FMT_OPEN_BINARY (1 << 30) #define MISC_FMT_CREDENTIALS (1 << 29) #define MISC_FMT_OPEN_FILE (1 << 28) But both appear to be entirely internally defined bits. I think these can all just be part of the enum, and we can quit mixing "&" tests and test_bit() calls: ... if (e->flags & MISC_FMT_OPEN_FILE) *dp++ = 'F'; *dp++ = '\n'; if (!test_bit(Magic, &e->flags)) { sprintf(dp, "extension .%s\n", e->magic); ... -- Kees Cook