Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp41894pxf; Wed, 17 Mar 2021 14:50:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJDeRY3RZB+7utpRqQ89EZd6xqhA1974SeV7w60ofjpbbtRf9ajqzjnpCppnG2lLt4wRum X-Received: by 2002:a05:6402:35cd:: with SMTP id z13mr44970993edc.21.1616017838700; Wed, 17 Mar 2021 14:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616017838; cv=none; d=google.com; s=arc-20160816; b=CA4TcoxZHKRm166p7PdlypDxuEb5R8khw+jcjmlIOmnzGKBzzaxg9laUQb9W21H8N0 T4VJrQjHfoCcMelpJDpRaII8q0i4Raq0z7BMc6FMFXZ0zvzW8oNjdP5Cdg8ZCD63N/ul /bL5r/dwGp9rbnZueba4SWTd+OGjX8uRVstTCGH9hX2jVwDFraJGBLzcxQDwkc6Po4Xx P+E4Ez1xKGi4t2IOqmtp78UW5AsOOjdnrs5xraNK3kAzj16fT8tW/YpxX6r4WL+fati8 OdFWD1+DL5BFWVAcL+kcqRpmCvgC/oZxcbWVK0hgykrcN4O9Fr9mS0wGab50DopD2NPR RG4g== 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=JcYcWHGmVNPGMhsAQmoPEgDMVOP5uAD1xio0p93SpaM=; b=vHDW/q/USbTEHkETjgtiRkwyR0dmvacGc6c8NdoN7xxmcf0OV8dVZ2gqmPGpeacp52 h/vsYqgUrT9YE5tMPz5rzhWK8X9JF6u6d8V3XvG8DPbkXHrtRzER6zIXYlytJfp0bnmB z2OvNgsDcT6US5HyhGoun+C19NkAIMaTBlK2mmko4QN6dPwyT/qUvzMoFEUdeeM10Rs7 D94dGC15sfilA2Iy4faw1sXY23Owv+J8CtZutQeL5vXBkNJD8dRiH7Kcep8eyazOm3le 9eu3SdXqJwPZT0UTeVwTH6p//oXod2bawxqGyiLZywoBk61l53a9JIhYoVAOeY8Ffe2O dCRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F2SGL0eb; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si26286ede.115.2021.03.17.14.50.16; Wed, 17 Mar 2021 14:50:38 -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=@chromium.org header.s=google header.b=F2SGL0eb; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbhCQVbG (ORCPT + 99 others); Wed, 17 Mar 2021 17:31:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbhCQVau (ORCPT ); Wed, 17 Mar 2021 17:30:50 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368DAC061760 for ; Wed, 17 Mar 2021 14:30:50 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id k24so64631pgl.6 for ; Wed, 17 Mar 2021 14:30:50 -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=JcYcWHGmVNPGMhsAQmoPEgDMVOP5uAD1xio0p93SpaM=; b=F2SGL0ebm1WN1AAXVrYPAflE0RRGNbDqRh5zWT6E/VDAvVhncHQW9rlh7inOf5XErV eT01CBORU4s/hPImJxaRVOnYWJURa/EpWjUwCeBqyX1w70HMPLVFmoVGwzzKxMu/dyNs /XSl3en+t+yMb+Vh+lIsSzolMrZwLO+UCWLC0= 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=JcYcWHGmVNPGMhsAQmoPEgDMVOP5uAD1xio0p93SpaM=; b=oikdUxfKpNAki/mboZCT4+0s75PNeEt+XACyZChou2WRULW5XEVsRgT6nLm4XH9Zl6 xQ8k7D+IWsol2GEIELTBtqnaTRlc4b/dSd2125tRI6lEjJcBmskbxMXfVSBCi1D7sKIc HyX4j/HrjQf0B+5yFwULcVFJiQKOxewShOWh47XzzvV/2M86x9qJoZOTHzg/mf6RpkEA tSFi/rdfuT5dzdEyYQyoPaD1eOU4hPDochSlbl8W4ArLh+m383eCtqD93aRJnXz4D13j 1GfwducnapuYYIymA0vjlYthPCEperk0Az5D96owCS5YL8h/tZs07v3xyzDi1Wi4CsQD gTzA== X-Gm-Message-State: AOAM530BWCCBVjTVvLLlTXLVAvGw4itvegMmejPl3XmI7dhk8p/b5AhB lFbaN1woDijTTxMJOFUlvFmjuQ== X-Received: by 2002:a05:6a00:78c:b029:1f5:d587:1701 with SMTP id g12-20020a056a00078cb02901f5d5871701mr889400pfu.59.1616016649608; Wed, 17 Mar 2021 14:30:49 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x190sm42856pfx.166.2021.03.17.14.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 14:30:48 -0700 (PDT) Date: Wed, 17 Mar 2021 14:30:47 -0700 From: Kees Cook To: Greg Kroah-Hartman Cc: Michal Hocko , Andrew Morton , Alexey Dobriyan , Lee Duncan , Chris Leech , Adam Nichols , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org, Uladzislau Rezki Subject: Re: [PATCH v2] seq_file: Unconditionally use vmalloc for buffer Message-ID: <202103171425.CB0F4619A8@keescook> References: <20210315174851.622228-1-keescook@chromium.org> <202103161205.B2181BDE38@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 17, 2021 at 04:38:57PM +0100, Greg Kroah-Hartman wrote: > On Wed, Mar 17, 2021 at 04:20:52PM +0100, Michal Hocko wrote: > > On Wed 17-03-21 15:56:44, Greg KH wrote: > > > On Wed, Mar 17, 2021 at 03:44:16PM +0100, Michal Hocko wrote: > > > > On Wed 17-03-21 14:34:27, Greg KH wrote: > > > > > On Wed, Mar 17, 2021 at 01:08:21PM +0100, Michal Hocko wrote: > > > > > > Btw. I still have problems with the approach. seq_file is intended to > > > > > > provide safe way to dump values to the userspace. Sacrificing > > > > > > performance just because of some abuser seems like a wrong way to go as > > > > > > Al pointed out earlier. Can we simply stop the abuse and disallow to > > > > > > manipulate the buffer directly? I do realize this might be more tricky > > > > > > for reasons mentioned in other emails but this is definitely worth > > > > > > doing. > > > > > > > > > > We have to provide a buffer to "write into" somehow, so what is the best > > > > > way to stop "abuse" like this? > > > > > > > > What is wrong about using seq_* interface directly? > > > > > > Right now every show() callback of sysfs would have to be changed :( > > > > Is this really the case? Would it be too ugly to have an intermediate > > buffer and then seq_puts it into the seq file inside sysfs_kf_seq_show. > > Oh, good idea. > > > Sure one copy more than necessary but it this shouldn't be a hot path or > > even visible on small strings. So that might be worth destroying an > > inherently dangerous seq API (seq_get_buf). > > I'm all for that, let me see if I can carve out some time tomorrow to > try this out. The trouble has been that C string APIs are just so impossibly fragile. We just get too many bugs with it, so we really do need to rewrite the callbacks to use seq_file, since it has a safe API. I've been trying to write coccinelle scripts to do some of this refactoring, but I have not found a silver bullet. (This is why I've suggested adding the temporary "seq_show" and "seq_store" functions, so we can transition all the callbacks without a flag day.) > But, you don't get rid of the "ability" to have a driver write more than > a PAGE_SIZE into the buffer passed to it. I guess I could be paranoid > and do some internal checks (allocate a bunch of memory and check for > overflow by hand), if this is something to really be concerned about... Besides the CFI prototype enforcement changes (which I can build into the new seq_show/seq_store callbacks), the buffer management is the primary issue: we just can't hand drivers a string (even with a length) because the C functions are terrible. e.g. just look at the snprintf vs scnprintf -- we constantly have to just build completely new API when what we need is a safe way (i.e. obfuscated away from the caller) to build a string. Luckily seq_file does this already, so leaning into that is good here. -- Kees Cook