Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1081534ybi; Fri, 31 May 2019 13:34:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJOmmZBEEIrn4cyQLfcJZjWNXw1/YL1VYnUA+/cuDRX884yXqnKWE4h8KMgg3s/mkkoDhB X-Received: by 2002:a17:902:9897:: with SMTP id s23mr9482915plp.139.1559334864843; Fri, 31 May 2019 13:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559334864; cv=none; d=google.com; s=arc-20160816; b=JIZ3ZIk5tByzvqiEX8t8ctTBVScjIJOj8wx0cT4z6DDhWJRXtrfBbqeSsz0eGL/Mnm j4/JZ3Xq/koiiWFl6TicVkLO1f1Z8gZ6EZxa9gZCu4wviVyH7gPj6pEmMcMFeDW2Hqqk jPvlVg7bxt1jwkQqLXXe8IQa6Xtl2ZtvT01m6DkWI70z/fDGRlYE8WbwBdIeDxXcIN+9 ogkAgoHOJBO2j3cU0R5WjBsYUmHOrcDhh+PB0040461cvliJotcKBkeb+S5h+kmByzUR eh7CeedsLlu+RBTIg4mUx9LBTBDBi6fDWY6cMR49xPYxRTYjnROLN9lGOfXxKOSIv1M8 MTRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=uy+PJdNhNNYWmW2SYbVenlVictCiccYq0JuoB6toabI=; b=kOPjnu1xbfQyUlvejjJeOUmsBOPf3aVlKP0SRWqcXZ+WQnCvxEFbx3NxCM+vouPvM7 /6erVBk2feV0BtaqWGe4Iq/T1flL9mOi7CAtNQgXTHBJVLbkqfDNquZz/upGTumY2ln0 xOLcD2HsTWh/UJ5lD3NgCCFg8YvbA9DUQSr92Mrs2cg1oVfc+4cSnJ6IabiJx3+fggOD r4R8PN+BOt77o5bzmZQPnRD8kVQESJJsVyJkQgVngWUv1YoGocNSpsvOQPHmlpQ6aeQT oNkHMtYIu2/beqNY6n/XUBrBNtck1zQ72cTCM4b9Zp94IO5zUtEW5bg00twp+2ObTnrq 44yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Jz9krRjs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si7302051plq.106.2019.05.31.13.34.08; Fri, 31 May 2019 13:34:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Jz9krRjs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727553AbfEaUdG (ORCPT + 99 others); Fri, 31 May 2019 16:33:06 -0400 Received: from mail-pg1-f178.google.com ([209.85.215.178]:46956 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727354AbfEaUdF (ORCPT ); Fri, 31 May 2019 16:33:05 -0400 Received: by mail-pg1-f178.google.com with SMTP id v9so4630747pgr.13 for ; Fri, 31 May 2019 13:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uy+PJdNhNNYWmW2SYbVenlVictCiccYq0JuoB6toabI=; b=Jz9krRjsm6lNZDVE3lzRiVxmi2w0/9Fv++xQ39+FzyKuSnfwcVVEeWJ+71t7Rms9La SG0OTtc0mdJFWmMSyPO+QMfBtOJbAYl2+qWlQYYr02+AFUg3FpQM5Dhl5CY4x0wgm/EB /74wjVVcMlWpZajDex8gRmJrMZaP9DS5SzoQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uy+PJdNhNNYWmW2SYbVenlVictCiccYq0JuoB6toabI=; b=VgHV9cGrFVsbwZGyQxLhv37/msrVqmwqBfavOEkoWGx4sxe/f8HmmPq4rRR4bDebOA /SrmMslTDNSWaq2TqQz3pMrJ78b76gQnIBp8aSfRH+LW9QXi7i/7E33UdL3RGqIsBExO /rZ8KvWKxNn/UGl4gGsEJ7K6Z3kovFN35LSbO95MaV8Ee6UMpfQfiQ7ZTVDuG1TZSdWy 2mabQskxBkYXGzLsrZBeAUKK4JaswFH7YfxgjMIcukaxKqnOPApmcmB1RCeBDuJCua7C t6YtB2Afghv/OwumxE768gE4dcGq+0jCawuzA5Hfm+WoAMGutPtMJRbwjZFBoB5qF49P rMog== X-Gm-Message-State: APjAAAV5uxHpQ3se/Lx5J7LUn9ga4LdR58P43caO9L2mfGXwJSkvzO9q 7x1Q22uKUU/t6Q2M2KI1Vd/BRA== X-Received: by 2002:a63:a34c:: with SMTP id v12mr11020501pgn.198.1559334785058; Fri, 31 May 2019 13:33:05 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a25sm213079pfn.1.2019.05.31.13.33.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 May 2019 13:33:04 -0700 (PDT) Date: Fri, 31 May 2019 13:33:02 -0700 From: Kees Cook To: Ke Wu Cc: Colin Ian King , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: security/loadpin: Allow to exclude specific file types Message-ID: <201905311330.EA6B6E5F@keescook> References: <73fac64c-fe49-4738-49a4-0afe668eed94@canonical.com> <201905310740.522B3A7C1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 31, 2019 at 11:03:17AM -0700, Ke Wu wrote: > I think Coverity is correct. Note that it's the size of > kernel_read_file_str (rather than exclude_read_files) doesn't equal to > ignore_read_file_id. > > This is because READING_MAX_ID is also an element in > kernel_read_file_str, which makes the size of kernel_read_file_str to > be READING_MAX_ID+1. I will send a new patch to fix the issue. Thanks > for the analysis! Ah! Yes, I see now. I was looking at the wrong things. It should be possible to just do: > > >> 209 for (j = 0; j < ARRAY_SIZE(kernel_read_file_str); j++) { for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++) and add a BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < ARRAY_SIZE(ignore_read_file_id)) for future robustness checking. Thanks for looking at this more closely! -Kees > > >> 210 if (strcmp(cur, kernel_read_file_str[j]) == 0) { > > >> 211 pr_info("excluding: %s\n", > > >> 212 kernel_read_file_str[j]); > > >> > > >> CID 81977 (#1 of 1): Out-of-bounds write > > >> overrun-local: Overrunning array ignore_read_file_id of 8 4-byte > > >> elements at element index 8 (byte offset 35) using index j (which > > >> evaluates to 8). > > >> > > >> 213 ignore_read_file_id[j] = 1; > > >> > > >> According to Coverity ignore_read_file_id is an array of 8 integers. > > >> However, ARRAY_SIZE(kernel_read_file_str) is 9, so we have an out of > > >> bounds write on ignore_read_file[j] when j is 8. > > > > > > What am I missing? This doesn't fail the build: > > > > > > + BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) != > > > + ARRAY_SIZE(ignore_read_file_id)); > > > > > > They have the same number of elements. > > > > > > > Yep, that's very true. I'll discuss this with Coverity as this seems > > like a weird false positive. > > > > Apologies for the noise. > > > > Colin > > > > -- > Ke Wu | Software Engineer | mikewu@google.com | Google Inc. -- Kees Cook