Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp276233imd; Fri, 26 Oct 2018 08:22:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5c/R+uZASukLs9zogLM4nwgDCixZu7KxiBlBnxGmpssXTTKcEbIG2z/Yd3l21Aqk/x6KfiJ X-Received: by 2002:a62:b209:: with SMTP id x9-v6mr4260988pfe.148.1540567331699; Fri, 26 Oct 2018 08:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540567331; cv=none; d=google.com; s=arc-20160816; b=KezVQi33Co0JdSOKd3ZnCW1cf8kpTgAokWFYga78jTwRilZrc1aZlK5cXkwDP7wZ9K BCtCZZUgEbwLBHLlRWKAHbbYbxn3MHOUmKUu0T0UxYN/ccRQVhyz1KCdApVZPKG5gNRy SYmbKK44Irmcvn7ubrquqQNPRllXqpbJpXn4Fa++MdUnPVpqG+VvXP8Ki27vz0etCdXC hhpxy167U32EHl+bqLXOgggq1PiBut9umYtHSvdbl3LVQnerIMoyoMTi2pJEfVnYxKWb JfA8Ynv3zXvOp1eB2x22CpUQLYaaLO/lfGPm39GazwmL5TAJ+dniSroq4e1rA1EB42BM yCRA== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=qJ1QkkvYuevMWoHJWSkHbZ2EZBzIsp25VhHZ2Ne7YA0=; b=zaAUeEKdP5gtxHQbBz3FJSas6jmaJ0QeSDiByb68z71pHoalszQSM7GCsmD/GKMzID tsCTQpdgUu+N9s2ZDdSIVNIh5RrTs6EOeqitHUs2KBm+EhiFDo4CoPEvLa4k5weR2fbT ZnizT2Vy6HCgBOM+Zqo3dMdd6W3J1/gdLXB5acz7gsMCCo/1e2bHCN7Av6gApEse7mAC 0u9v1G1Ui0vmkjhilIE97xujIF50SoNqoFGpZKQCTE040N1YT3cUzSV7gAsiLcKo5Zp/ /uZcfyvXmUMXoQTN1XPYBgWgOigPmcYM26TBSciVtUs8BEKK2vblzS4ivdfbN/w2v6xp b0xg== ARC-Authentication-Results: i=1; mx.google.com; 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 y5-v6si2966583pgo.310.2018.10.26.08.21.54; Fri, 26 Oct 2018 08:22:11 -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; 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 S1726763AbeJZX6w (ORCPT + 99 others); Fri, 26 Oct 2018 19:58:52 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36176 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbeJZX6v (ORCPT ); Fri, 26 Oct 2018 19:58:51 -0400 Received: by mail-pg1-f195.google.com with SMTP id z17-v6so698573pgv.3; Fri, 26 Oct 2018 08:21:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=qJ1QkkvYuevMWoHJWSkHbZ2EZBzIsp25VhHZ2Ne7YA0=; b=IfECETKIuE19C/mRfTAOPLL5xXh5TpKlYxBHNxY7vCDRchWGvgpN1plhkgU614A/9i L59agRdLvBK+UR4j0TNwaRssHZhSRSZQl7qzw3LPE+NEWUVQDyjImiDUPjB89JtvFN7l 73k41JWWsolkDc+wEHZJmKzm4GcNnwr6rnKRnbuILdgwYpOHVB5LyZUKjdZo2+G3SRsU Vor3DadGesDlUmNFnPM6ElCmZBzHpAZ0RFAhWXg3ujfHnUyTfSTs4nHjjGzzmVuJ5Ewa 7vxlVmYY9iF9sBsomk706mXhqxhjo8BMPfmRDoA94GvVc7wMMIcTs0jY9jJ07eUJ+oQ1 5eOg== X-Gm-Message-State: AGRZ1gKoAGE31YRMNNs/9NQ2VR684N3/HB9rVj52sL4SCA3c8u79vcEt Ag3wGW1M3MMfcT0dJPzjnuw= X-Received: by 2002:a63:a84a:: with SMTP id i10mr3931893pgp.263.1540567283520; Fri, 26 Oct 2018 08:21:23 -0700 (PDT) Received: from ?IPv6:2620:15c:2cd:203:5cdc:422c:7b28:ebb5? ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id d65-v6sm15668362pfe.42.2018.10.26.08.21.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 08:21:21 -0700 (PDT) Message-ID: <1540567279.66186.99.camel@acm.org> Subject: Re: [PATCH] floppy: Avoid memory access beyond the array bounds in setup_rw_floppy() From: Bart Van Assche To: Kyungtae Kim , Jens Axboe Cc: jikos@kernel.org, Byoungyoung Lee , DaeRyong Jeong , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 26 Oct 2018 08:21:19 -0700 In-Reply-To: References: Content-Type: text/plain; charset="UTF-7" X-Mailer: Evolution 3.26.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-10-26 at 10:39 -0400, Kyungtae Kim wrote: +AD4 setup+AF8-rw+AF8-floppy() writes some bytes of array cmd to the floppy disk +AD4 controller, depending on cmd+AF8-count. +AD4 Although the size of array cmd is fixed like 16, cmd+AF8-count can be much +AD4 larger through raw+AF8-cmd+AF8-ioctl(). +AD4 Noticed there is no bound check for this, thereby leading to invalid +AD4 memory access. Against which kernel tree did you prepare this patch? Just above the code you want to insert I found the following: if (ptr-+AD4-cmd+AF8-count +AD4 33) ... Why does that statement compare cmd+AF8-count with 33? Is that comparison correct or not? Anyway, I don't think it makes sense first to compare cmd+AF8-count against 33 and next to compare it against 16 ... +AD4 +- if (ptr-+AD4-cmd+AF8-count +AD4 ARRAY+AF8-SIZE(ptr-+AD4-cmd)) +AD4 +- return -EINVAL+ADs This comparison looks suspicious to me. Almost every comparison of the type +ACI... +AD4 ARRAY+AF8-SIZE()+ACI I have seen so far was wrong and should be changed into +ACI... +AD4APQ ARRAY+AF8-SIZE()+ACI instead. Bart.