Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1126986ybg; Thu, 4 Jun 2020 01:31:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3pvSDutAxCWKalbabQfQLdhpMk8hoD4qnOthQppTlTr9JLFEqaG5rJnX1lhWs/9HgBj9T X-Received: by 2002:a05:6402:228d:: with SMTP id cw13mr3441581edb.150.1591259497590; Thu, 04 Jun 2020 01:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591259497; cv=none; d=google.com; s=arc-20160816; b=ezkjEi0TikxV7ZUvmlEB0UNYWlaxgQ02Hd4Fn9qVoOREDUQJQEtGyIEeyEylscb6DV yEgFNU9AaX6qyaC2AOWX7X9eGam0IvJHt66KbCtqCng/whZyJAxZK6rwAoIYvlENg8JJ pszZIy8Ci21kGhFfOvH2BPvCo7AMd7t0k+XqjzWEeCbHANib5o0xX92Kq1O1wNeoJPdO fUGkn1YOzC/VLgEicyyB6V6F4xwk4GP/NCNotB5WyYE+niQwIfe+9YU6wPKzELrywGMO GZfQxdhGK8qrwn+z78qegVZcKhaUM9YklnY9cBtkxH41dHsvBA2gKaDcE7BUrPph0Pq/ PSaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PKk1J+LKsQnN71HxmGj+GvS1I8q6haqL05yr0+A1nbc=; b=RaKM4esk7ovcLMRPJ1Vu5bbKvjjWUWzHenaKNR1b2asX+I9tenj5wspVd1Ah7GMR04 4svwSRM2xERl7e7XqZ2+30nf2TOWnlNSvQ2JjxaiwlIkMwweamSmgaY1yHIbzecmn0Be RoGFAbiGNRsS6vn5LupJ1k2/KNcwpEKnxednMNdgtbDJKXKygo7bDTJteU0Ojretw172 1GXUg01CLTBfawJA5K7XoATR9Bvd3K2BDvagXCPIDue/aSevzUO7l6K6IN+znq5vTBE0 kp+FZkpzhuOMS2zvj3rrk0cbuAu9R6tpeR6MnQryNTkEYSADzBmitAUfr/CL8GWFuzRF JQCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WtU+u7SA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si1314999ejs.242.2020.06.04.01.31.14; Thu, 04 Jun 2020 01:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WtU+u7SA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727911AbgFDI3E (ORCPT + 99 others); Thu, 4 Jun 2020 04:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgFDI3D (ORCPT ); Thu, 4 Jun 2020 04:29:03 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D24C05BD1E for ; Thu, 4 Jun 2020 01:29:03 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id p5so5067843wrw.9 for ; Thu, 04 Jun 2020 01:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=PKk1J+LKsQnN71HxmGj+GvS1I8q6haqL05yr0+A1nbc=; b=WtU+u7SAU/10RONQscOH90M1y5frlrcns0jI0jk4A+ZGLxcINgOAebeV7SVyJoudZ4 K2IxCfLAEob4lqVbfMdHz1pWGbs1L9RHPpMdfSZGyusCdj6fqOGJEuSw7YETgMCD2b9g oxySnMad83p3lROkqgkJzMqyh1nWE5+aZnHO3JLroi+Caob04IEIHdfCM0Sv3nNtN5yy Xnsj54Ic6qGuSJoryz6neW86cVs5lZ8BKWpK7uPqNIxzKZ3YHT8NwxpBhhqNSoR2bNGB k6r2KuJSh/jDO5Ttz6HUwWcN/4yi0HB2UxQJvlP8HaIAZXOCrXLzbdr0vxK6iaXXGpFQ BQYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=PKk1J+LKsQnN71HxmGj+GvS1I8q6haqL05yr0+A1nbc=; b=C9rm0qnmYUgmmEVQeD5Tjmz/OrWdrk8k7cBPtPWghLHph49NRqGUaETvf1JqJ05bqv xeH1suTsJmK4hXZyCeul+V5FY0kkv2M7k9PpGT+CNiI7W4eoS4BNiZqUJWyrpx+0vmAQ CQj67iPIrdkJ+cXPE+7QFAUw61FtMibXKtY3jYWFxGh3NGV6MBBIwUNgMCtV2GPT7cqy pMze1XKGqXbU3u6sghDKEncS2s0dIZNtJ2soMOc4zPkKh7YZ+dnKvChYXHbCUBcr5W0Q eE80XqlYqcJGQcKhedmK+EoZzTQ+u+LNxSt+VC0fyu6RY322FhkCLkWWfKzrUf5oFbtT aATQ== X-Gm-Message-State: AOAM532oSlw60c1HIL6TdTWBL41q9zrrEpvQuig3+/KnYBUKafR+w2AL ODGiBa53nEGDyreKAu4xMCcWQYObzobo6BfWyJRHNg== X-Received: by 2002:a5d:4282:: with SMTP id k2mr3211795wrq.196.1591259342120; Thu, 04 Jun 2020 01:29:02 -0700 (PDT) MIME-Version: 1.0 References: <20200603174714.192027-1-glider@google.com> <20200603214633.GF48122@redhat.com> In-Reply-To: <20200603214633.GF48122@redhat.com> From: Alexander Potapenko Date: Thu, 4 Jun 2020 10:28:50 +0200 Message-ID: Subject: Re: [PATCH] ovl: explicitly initialize error in ovl_copy_xattr() To: Vivek Goyal Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, LKML , Kees Cook , Roy Yang , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 3, 2020 at 11:46 PM Vivek Goyal wrote: > > On Wed, Jun 03, 2020 at 07:47:14PM +0200, glider@google.com wrote: > > Under certain circumstances (we found this out running Docker on a > > Clang-built kernel with CONFIG_INIT_STACK_ALL) ovl_copy_xattr() may > > return uninitialized value of |error| from ovl_copy_xattr(). > > If we are returning uninitialized value of error, doesn't that mean > that somewhere in the function we are returning without setting error. > And that probably means that's a bug and we should fix it? Could be. My understanding of that code is quite limited, so I'm happy to change the patch if necessary. > I am wondering if this is triggered by loop finishing because all > the xattr on the file are ovl_is_private_xattr(). Yes, that's the case. The loop makes one iteration, then ovl_is_private_xattr() returns true, then the loop ends. > In that case, we > will come out of the loop without setting error. This is in fact > success and we should return 0 instead of some random error? Thanks for letting me know. I'll change that to 0 then. > Thanks > Vivek > > > > It is then returned by ovl_create() to lookup_open(), which casts it to > > an invalid dentry pointer, that can be further read or written by the > > lookup_open() callers. > > > > Signed-off-by: Alexander Potapenko > > Cc: Kees Cook > > Cc: Roy Yang > > Cc: # 4.1 > > > > --- > > > > It's unclear to me whether error should be initially 0 or some error > > code (both seem to work), but I thought returning an error makes sense, > > as the situation wasn't anticipated by the code authors. > > > > The bug seem to date back to at least v4.1 where the annotation has bee= n > > introduced (i.e. the compilers started noticing error could be used > > before being initialized). I hovever didn't try to prove that the > > problem is actually reproducible on such ancient kernels. We've seen it > > on a real machine running v4.4 as well. > > --- > > fs/overlayfs/copy_up.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c > > index 9709cf22cab3..428d43e2d016 100644 > > --- a/fs/overlayfs/copy_up.c > > +++ b/fs/overlayfs/copy_up.c > > @@ -47,7 +47,7 @@ int ovl_copy_xattr(struct dentry *old, struct dentry = *new) > > { > > ssize_t list_size, size, value_size =3D 0; > > char *buf, *name, *value =3D NULL; > > - int uninitialized_var(error); > > + int error =3D -EINVAL; > > size_t slen; > > > > if (!(old->d_inode->i_opflags & IOP_XATTR) || > > -- > > 2.27.0.rc2.251.g90737beb825-goog > > > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg