Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp771394ybl; Wed, 4 Dec 2019 10:34:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyJwfYyEa1eOinkUQe3xyyzQRnc0vk4MyJGros+x96USB5AGue1jaDz/vvM2avnPQdjUXPg X-Received: by 2002:a05:6830:1185:: with SMTP id u5mr3390613otq.147.1575484488377; Wed, 04 Dec 2019 10:34:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575484488; cv=none; d=google.com; s=arc-20160816; b=gNuX08cdVoBXGQ+pPTnWt6QF6iKpKnJPC3oTKkvuatB6AsK4Y53WaVhsC1sxjtNi46 Gu6Ihx0t/AzMtQ2rJha75My9v+pTdC3O7RW0+pPJ0zDmR0PXbZ3VD4ZgPHK3kCM8dECD x2lotvc7q+Mc8raZpg18ZEYQaVqnbcaxWI5/EuBGUzqnuYd5jijU4so7t4dQOm4WkIRk gwElwGeoky7rItbz07oOTNq9BGUWgX+GZJvLlPR1JJXfprCj1EZpR8P/cscv7lO6LlXx av/vujWrVmVQKsulUEgKupcDtBu9qCZk5g5o5k3pinmZRONR1diqNJn9g9DyQKIbVppj iZyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FPiBy3e3zUg0m4K/nRiHT6Vw6UdUbtEDAqlj3R5valo=; b=Ss/PV8R7PwWJeIz8Nwk5QKK0lsJqQDTSak/RlTl72V7d6DQwfXJgBGg44NywC2zgY3 jAWk8ddZdV8x5bdy+BlW57nkCvvfoDbsTxbTZUWQn0gPO2kMucN2VVApBRQ9Gk9+3lkn ht7epmmN0ZYn++w5ypFeGhH3spTXOHryr2c2bJ5I5obOiCmhxnhay01p8O9hAUEpD3tT VDGKt3G/4Gsk86NsyEQNosv/jzr6m9Vumwm+Y/yv6Zrtq8YLNFilJ+VP7cigO40rS1Nq wUg62rRaeGTSE4I23Jzc/ktvF0Mmb6gYBRzaRRhSuXAN+hjNHPM3q7zaJXo81EFE1K6Z 0Eqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Djtns5IV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n139si3754704oig.121.2019.12.04.10.34.34; Wed, 04 Dec 2019 10:34:48 -0800 (PST) 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=@linux-foundation.org header.s=google header.b=Djtns5IV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728388AbfLDSdQ (ORCPT + 99 others); Wed, 4 Dec 2019 13:33:16 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46854 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728204AbfLDSdQ (ORCPT ); Wed, 4 Dec 2019 13:33:16 -0500 Received: by mail-lf1-f66.google.com with SMTP id a17so317272lfi.13 for ; Wed, 04 Dec 2019 10:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FPiBy3e3zUg0m4K/nRiHT6Vw6UdUbtEDAqlj3R5valo=; b=Djtns5IVsjsKkjqXlXecLgmq7TLzrMkrPSgPEVr/ZvwmJI4iaDca3o5iA6ZgsfgxEU Hpfx40UcKXq7pbBcMond4TGqgXSpVLfIVObpgFXwaKdlBXgs60PfyOM2EclUBrVxZy+I VKVVd/1vx0Caofr6kXg8TOm9f33WEMkE4r42w= 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; bh=FPiBy3e3zUg0m4K/nRiHT6Vw6UdUbtEDAqlj3R5valo=; b=OFPe8nXhcY+p0Blgwy3zwS86/eWT7mY3ThgRfz9PmsbS72Up8bxiENX/TrLMmBA3GX qg8I7RR8yLRreBKbaAlYVejLS1YDBXHl+Ci1L+34Uj2I4JZQUX3TiIiH4va7ZL6uuHGJ 7+vO7Hi0TQ1NKfjrR2yAJ3piKA2onMU1E3vvkpmwxBopaPjgHTVby1f4y6lwgu3133QF SUnPYy0XYcFl6lkpkuEBCPDRk8pts0oFuy1JLG5itfwO0VWur+J9ZO6Yb/5Vy4OpEcTJ bBryKHgKJisbnvYRmtNT/AeI0W5hlVi6uygeDFDA+xOmlcGj85pS88vgIX7KcGqHMW8I R6HQ== X-Gm-Message-State: APjAAAXyKk2f6As8pUkh/PCKrA+V6KijuyS4yKFjZPuCdslzJxlh6miN IaqMFLrMbdnwv/Wa61aSEqvD7vuJMB8= X-Received: by 2002:ac2:5ec3:: with SMTP id d3mr2946745lfq.176.1575484394290; Wed, 04 Dec 2019 10:33:14 -0800 (PST) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id f7sm3589090ljp.62.2019.12.04.10.33.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2019 10:33:13 -0800 (PST) Received: by mail-lf1-f50.google.com with SMTP id a17so317210lfi.13 for ; Wed, 04 Dec 2019 10:33:13 -0800 (PST) X-Received: by 2002:ac2:555c:: with SMTP id l28mr2926109lfk.52.1575484392762; Wed, 04 Dec 2019 10:33:12 -0800 (PST) MIME-Version: 1.0 References: <20191204140812.2761761-1-arnd@arndb.de> In-Reply-To: <20191204140812.2761761-1-arnd@arndb.de> From: Linus Torvalds Date: Wed, 4 Dec 2019 10:32:56 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] scsi: sg: fix v3 compat read/write interface To: Arnd Bergmann Cc: James Bottomley , Al Viro , Andrew Morton , linux-scsi , linux-kernel , Doug Gilbert Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 4, 2019 at 6:08 AM Arnd Bergmann wrote: > > To address both of these, move the definition of compat_sg_io_hdr > into a scsi/sg.h to make it visible to sg.c and rewrite the logic > for reading req_pack_id as well as the size check to a simpler > version that gets the expected results. I think the patch is a good thing, except for this part: > @@ -575,6 +561,14 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) > int err = 0, err2; > int len; > > +#ifdef CONFIG_COMPAT > + if (in_compat_syscall()) { > + if (count < sizeof(struct compat_sg_io_hdr)) { > + err = -EINVAL; > + goto err_out; > + } > + } else > +#endif > if (count < SZ_SG_IO_HDR) { > err = -EINVAL; > goto err_out; Yes, yes, I know we do things like that in some other places too, but I really detest this kind of ifdeffery. That } else #endif if (count < SZ_SG_IO_HDR) { is just evil. Please don't add things like this where the #ifdef section has subtle semantic continuations outside of it. If somebody adds a statement in between there, it now acts completely wrong. I think you can remove the #ifdef entirely. If CONFIG_COMPAT isn't set, I think in_compat_syscall() just turns to 0, and the code gets optimized away. Hmm? Linus