Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2725221rwb; Fri, 2 Dec 2022 14:11:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf7GGBC/zgBE1NXzmeiDhYmV1na4JaOuj0TiCgm03pWohIpVTs/t4zkEwjU2g8xO8QutQUbk X-Received: by 2002:a17:902:708a:b0:189:7372:1451 with SMTP id z10-20020a170902708a00b0018973721451mr34863666plk.122.1670019062727; Fri, 02 Dec 2022 14:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670019062; cv=none; d=google.com; s=arc-20160816; b=lQXJXl0YYHFLm5SaHfPzu4/qfK6Umz3DsL4J3LHTN8dz5cEKKYiwZiSbv8KDtNYqg3 5trzjtuV6inLgtL7KWsmLtCwA5Mv0e1E2Xm1Nc3Rm1n2r8JEyqIlEBQN3lpbrjRX0Dhe cOh6OPo3sZ6cTVKzLaN/8OVZ8HeA+Lkd4FSGNLym3sNcHLcAJXSw/066dhNjIMpb3H+k OK4FD59vx8gTL6mM9FS+vkYiq5zTJzklQQbV4wr2jqs4vlwKtLHWx+HxCLNXZMKaFgxe GH/wK8gMuUMPb7dSTtNxGW1SDI6JNqN8ozPxBOmDxnlJ1TKUw6/G3xA+SeKFNAUYx26q MXWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=t/wakp1HXP8TMhCgpZ+F2SUDPBBbIjX7REGlztKJoc8=; b=CLAW6/zAiNoFrJ7ccaJN191B/elSchs3ba1o2yAwb2mheulbhOx4ywjnBvOxiu/NRm ET4Dtp2c4XXnkBtIN5vGYjLQpV51FpL/Y/iF3XveBT+QyYjvw+4g24qwzzUlU0/vd25i 3t8mzR/aExEaxMhSdrhKNOHVHtAGGK47f3D58ET3my3X7a4oXyhufMeQAtYemDL5ZxPd tFpvXY2Yf55sT9t3Dtp6UyYgM0OWVWXYj189vqsCaEEPnvPHyiFxfEBTX4CqmUjbnRr8 AOTJ6hKp7C7HHHABSzGaplhRUoFORZbbX34bFh1K75JCxY8BbAdKBj+FXuAN0Y+eBZm7 1MiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=URC9xhK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25-20020a631559000000b0046ece301e82si8404831pgv.756.2022.12.02.14.10.52; Fri, 02 Dec 2022 14:11:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=URC9xhK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234290AbiLBVzk (ORCPT + 82 others); Fri, 2 Dec 2022 16:55:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbiLBVzh (ORCPT ); Fri, 2 Dec 2022 16:55:37 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66EFD80CD for ; Fri, 2 Dec 2022 13:55:36 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id l127so5466969pfl.2 for ; Fri, 02 Dec 2022 13:55:36 -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=anHCrAAz4p2eNXfxCAd81xQTwzZU1L6im41FZUzc5+rK01WAk4zLb4ZWJiauOzF5mG yHDx+gdqnRs243MDkXz3vuhr9IBR9X+5lS3HsSSCWT6NL8itqIyv35BL0gYPSerMK3zP R4kT198who5A022avmyJ0MQxjLto0jHp6qxz1MUcU8ce2bX9zI6Ec9frkNSmXU1WLmGZ 3j1gtE+mmHjwk2vRIeBZOI3HqnBSrlzTAZOBwEOVHvjNv8vo3Tm/HltJIYosPwU2aG5y /EjZUFA0J/E67xLcrXyQghGvcgooqQGwOuRqvJR4JoSey+xYn72marX9PzSnZAIM36gs pXqQ== X-Gm-Message-State: ANoB5pmjdTRfhVJLPgvrybTdeYanGYWrUIsAVGBZPnszkKzM6DqgFDfv uzsC2BSnHxEYTg4qOfHvOlVqkg== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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