From patchwork Thu Feb 8 08:44:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549437 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C02CC6BFD4; Thu, 8 Feb 2024 08:45:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381924; cv=none; b=JmzeBzGis5wlIITSZ5K6Z6J2Gv7NOhObLPPd5hiKKpLUv3rzKjm7KDse/vIU6nvakgKa4ZEoMCyiWLKOBMmJ2JhGISEr3jVufmdZoeI2ucn2x1KB7iJi1gRvtTwiQuyCXJG8g0fvDvtQyVkOOU+xNBQj38tBatTs3s3we/zqxp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381924; c=relaxed/simple; bh=wv1edZDay1984m0Qu877d4pMp2VycX7eTW+TWnSEgGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=liiQnLPXN9ko834KsN6N1YGPOCWVBHCbEiFzGawf2aTbK4ps9TK4P0+jYmoZqcER6hARLjvJo0Ls7Aa2NmIPEhTqX1/Wis4ED3jaUb7JvKonklqrrRLeSk9ocLSKbVfjCnkRX3YpT4y7m9r7OrlUgbxgFVmPbRrYQWO6XbfJOyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KU3PEYfL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KU3PEYfL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A033BC433F1; Thu, 8 Feb 2024 08:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381923; bh=wv1edZDay1984m0Qu877d4pMp2VycX7eTW+TWnSEgGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KU3PEYfLT6P4J4Z+OLwcXn2yaoKj9oYGZt/jp0y6WWO8GaVbkWKi3tykEDq7QtCPC jlsBBIPRRHQHaZ1E1EkEsy51RAFNNuuY+NPszom6UcRh30mblvuBOgH9aoSgeK9P4v KzPpm0ApERis84nYdrb/0rI5ASwBIKDrxNpCf5pGtMp9qcBVgXYXRiF+DCK4zo6yjq cNyOveBeuFvaXZGwbzKDZHTFHkDPeXrGuLZfKz3Nks1XvKAmRFiiuSJT6L8O7eapPB D1yfoYzw2DgSfYelyXJjm46z6ehLXMNmW7EUAml+pHfg3PgZWQ3vzDcCGYDpl2RJlQ 2nGJSsnDocs7w== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Adam Radford , Joel Jacobson , de Melo , Andre Hedrick Subject: [PATCH 01/10] scsi: 3w-xxxx: Trivial: Remove trailing whitespace Date: Thu, 8 Feb 2024 08:44:13 +0000 Message-ID: <20240208084512.3803250-2-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since 5a602de99797b ("Add .editorconfig file for basic formatting") my editor has been forced to remove trailing whitespace from any file it saves. Instead of fighting this recent kernel default, let's start chipping away at fixing the issues. Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Adam Radford Cc: Joel Jacobson Cc: de Melo Cc: Andre Hedrick --- drivers/scsi/3w-xxxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c index 2c0fb6da0e608..13ddc97f5a623 100644 --- a/drivers/scsi/3w-xxxx.c +++ b/drivers/scsi/3w-xxxx.c @@ -1099,7 +1099,7 @@ static int tw_initconnection(TW_Device_Extension *tw_dev, int message_credits) command_packet->request_id = request_id; command_packet->status = 0x0; command_packet->flags = 0x0; - command_packet->byte6.message_credits = message_credits; + command_packet->byte6.message_credits = message_credits; command_packet->byte8.init_connection.response_queue_pointer = 0x0; command_que_value = tw_dev->command_packet_physical_address[request_id]; From patchwork Thu Feb 8 08:44:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549438 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E236D1AB; Thu, 8 Feb 2024 08:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381925; cv=none; b=I/sf50vDrgytaV9UgceEUCV0V+fCZzEKYS9+/8VrKMAXX8DlK1fJdSdOB1tMaGSog9S0FTq6i5Fa2kqSZo6bsx+O1dOuTot+pBYh79/J2wehg5ZJvY+iPbztpe76lJl+LmL/t/7VU4/CxL9cNVcajiSd447CLd684vzi3eqXAGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381925; c=relaxed/simple; bh=gBFO/9DVXohiBgwRjVJTNp1nlX5W18BmmjuIIQEzyeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DM2nzGmYalmZEH4krDHQtXJ1iF1wJjtTxrnyc0AcvHWNPgBffSl/6BvI9bB8uurrESlIXhhyuVuTVzdcP0bvj3Ufska2Re2Gc8R9B92UT7X0hd9EzDRhDCUUDPBbINg6Jy2UuKdi+7MdH/rN0dNSDcTiKcjfz2y3jnZ9G8j70zw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pgoENIZx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pgoENIZx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F2CDC43394; Thu, 8 Feb 2024 08:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381925; bh=gBFO/9DVXohiBgwRjVJTNp1nlX5W18BmmjuIIQEzyeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pgoENIZxGJWTBQr7a7M7KnxHYBZyDq62VZ7lmpu16WXA74+4Efb2hoqvNpFpcFZ3Y P6EYi93XV9UL3Ltc7te1XnhET3poLKQGwMYKHdPsNGyiPX/yufOFw66ZbWmMEamkkR CAFcoEPrX65+rBoWG6TMNMfEJ8yV3Vo27urGiQpjRLQ4fJuDvlM+bBVapwUbO2kb8i 50Zuk8MLN4o9bO9Fy2HWNlfk9n32B/Fk0PgFIRn9DThq1CQ4qDp7XgrTpyD/gapmT2 0dgo1HXY3KO+1zK0wn69R8jVXpVELFqMxxd0e3dlIhnG5LFgx7jHSW46ReDsjDeqcK x0g+QKJ73Fftg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Richard Hirst Subject: [PATCH 02/10] scsi: 53c700: Trivial: Remove trailing whitespace Date: Thu, 8 Feb 2024 08:44:14 +0000 Message-ID: <20240208084512.3803250-3-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since 5a602de99797b ("Add .editorconfig file for basic formatting") my editor has been forced to remove trailing whitespace from any file it saves. Instead of fighting this recent kernel default, let's start chipping away at fixing the issues. Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Richard Hirst --- drivers/scsi/53c700.c | 102 +++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c index 85439e976143b..1aa933485719a 100644 --- a/drivers/scsi/53c700.c +++ b/drivers/scsi/53c700.c @@ -4,7 +4,7 @@ * * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com **----------------------------------------------------------------------------- -** +** ** **----------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ * * The 700 is the lowliest of the line, it can only do async SCSI. * The 700-66 can at least do synchronous SCSI up to 10MHz. - * + * * The 700 chip has no host bus interface logic of its own. However, * it is usually mapped to a location with well defined register * offsets. Therefore, if you can determine the base address and the @@ -61,7 +61,7 @@ * consistent memory allocation. * * Version 2.5 - * + * * More Compatibility changes for 710 (now actually works). Enhanced * support for odd clock speeds which constrain SDTR negotiations. * correct cacheline separation for scsi messages and status for @@ -70,7 +70,7 @@ * * Version 2.4 * - * Added support for the 53c710 chip (in 53c700 emulation mode only---no + * Added support for the 53c710 chip (in 53c700 emulation mode only---no * special 53c710 instructions or registers are used). * * Version 2.3 @@ -190,7 +190,7 @@ static char *NCR_700_condition[] = { "DISCONNECT_MSG RECEIVED", "MSG_OUT", "DATA_IN", - + }; static char *NCR_700_fatal_messages[] = { @@ -260,7 +260,7 @@ NCR_700_offset_period_to_sxfer(struct NCR_700_Host_Parameters *hostdata, static inline __u8 NCR_700_get_SXFER(struct scsi_device *SDp) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0]; return NCR_700_offset_period_to_sxfer(hostdata, @@ -416,7 +416,7 @@ NCR_700_detect(struct scsi_host_template *tpnt, int NCR_700_release(struct Scsi_Host *host) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)host->hostdata[0]; if (hostdata->noncoherent) @@ -449,7 +449,7 @@ NCR_700_identify(int can_disconnect, __u8 lun) * Inputs : host - SCSI host */ static inline int NCR_700_data_residual (struct Scsi_Host *host) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)host->hostdata[0]; int count, synchronous = 0; unsigned int ddir; @@ -461,16 +461,16 @@ NCR_700_data_residual (struct Scsi_Host *host) { count = ((NCR_700_readb(host, DFIFO_REG) & 0x3f) - (NCR_700_readl(host, DBC_REG) & 0x3f)) & 0x3f; } - + if(hostdata->fast) synchronous = NCR_700_readb(host, SXFER_REG) & 0x0f; - + /* get the data direction */ ddir = NCR_700_readb(host, CTEST0_REG) & 0x01; if (ddir) { /* Receive */ - if (synchronous) + if (synchronous) count += (NCR_700_readb(host, SSTAT2_REG) & 0xf0) >> 4; else if (NCR_700_readb(host, SSTAT1_REG) & SIDL_REG_FULL) @@ -500,7 +500,7 @@ sbcl_to_string(__u8 sbcl) ret[0]='\0'; for(i=0; i<8; i++) { - if((1<state != NCR_700_SLOT_FREE) /* should panic! */ printk(KERN_ERR "BUSY SLOT ON FREE LIST!!!\n"); - + hostdata->free_list = slot->ITL_forw; slot->ITL_forw = NULL; @@ -546,11 +546,11 @@ find_empty_slot(struct NCR_700_Host_Parameters *hostdata) slot->state = NCR_700_SLOT_BUSY; slot->flags = 0; hostdata->command_slot_count++; - + return slot; } -STATIC void +STATIC void free_slot(struct NCR_700_command_slot *slot, struct NCR_700_Host_Parameters *hostdata) { @@ -560,7 +560,7 @@ free_slot(struct NCR_700_command_slot *slot, if(slot->state == NCR_700_SLOT_FREE) { printk(KERN_ERR "53c700: SLOT %p is FREE!!!\n", slot); } - + slot->resume_offset = 0; slot->cmnd = NULL; slot->state = NCR_700_SLOT_FREE; @@ -654,7 +654,7 @@ NCR_700_internal_bus_reset(struct Scsi_Host *host) STATIC void NCR_700_chip_setup(struct Scsi_Host *host) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)host->hostdata[0]; __u8 min_period; __u8 min_xferp = (hostdata->chip710 ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP); @@ -694,11 +694,11 @@ NCR_700_chip_setup(struct Scsi_Host *host) } else { NCR_700_writeb(BURST_LENGTH_8 | hostdata->dmode_extra, host, DMODE_700_REG); - NCR_700_writeb(hostdata->differential ? + NCR_700_writeb(hostdata->differential ? DIFF : 0, host, CTEST7_REG); if(hostdata->fast) { /* this is for 700-66, does nothing on 700 */ - NCR_700_writeb(LAST_DIS_ENBL | ENABLE_ACTIVE_NEGATION + NCR_700_writeb(LAST_DIS_ENBL | ENABLE_ACTIVE_NEGATION | GENERATE_RECEIVE_PARITY, host, CTEST8_REG); } else { @@ -731,7 +731,7 @@ NCR_700_chip_setup(struct Scsi_Host *host) NCR_700_writeb(ASYNC_DIV_3_0 | hostdata->dcntl_extra, host, DCNTL_REG); hostdata->sync_clock = hostdata->clock*2; hostdata->sync_clock /= 3; - + } else if(hostdata->clock > 37 && hostdata->clock <= 50) { /* sync divider 1, async divider 2 */ DEBUG(("53c700: sync 1 async 2\n")); @@ -764,7 +764,7 @@ NCR_700_chip_setup(struct Scsi_Host *host) STATIC void NCR_700_chip_reset(struct Scsi_Host *host) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)host->hostdata[0]; if(hostdata->chip710) { NCR_700_writeb(SOFTWARE_RESET_710, host, ISTAT_REG); @@ -774,7 +774,7 @@ NCR_700_chip_reset(struct Scsi_Host *host) } else { NCR_700_writeb(SOFTWARE_RESET, host, DCNTL_REG); udelay(100); - + NCR_700_writeb(0, host, DCNTL_REG); } @@ -790,7 +790,7 @@ NCR_700_chip_reset(struct Scsi_Host *host) * ACK) so that the routine returns correctly to resume its activity * */ STATIC __u32 -process_extended_message(struct Scsi_Host *host, +process_extended_message(struct Scsi_Host *host, struct NCR_700_Host_Parameters *hostdata, struct scsi_cmnd *SCp, __u32 dsp, __u32 dsps) { @@ -816,15 +816,15 @@ process_extended_message(struct Scsi_Host *host, spi_offset(starget) = offset; spi_period(starget) = period; - + if(NCR_700_is_flag_set(SCp->device, NCR_700_DEV_PRINT_SYNC_NEGOTIATION)) { spi_display_xfer_agreement(starget); NCR_700_clear_flag(SCp->device, NCR_700_DEV_PRINT_SYNC_NEGOTIATION); } - + NCR_700_set_flag(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC); NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION); - + NCR_700_writeb(NCR_700_get_SXFER(SCp->device), host, SXFER_REG); @@ -841,7 +841,7 @@ process_extended_message(struct Scsi_Host *host, resume_offset = hostdata->pScript + Ent_SendMessageWithATN; } break; - + case A_WDTR_MSG: printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited WDTR after CMD, Rejecting\n", host->host_no, pun, lun); @@ -1121,7 +1121,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, SCp = scsi_host_find_tag(SDp->host, hostdata->msgin[2]); if(unlikely(SCp == NULL)) { - printk(KERN_ERR "scsi%d: (%d:%d) no saved request for tag %d\n", + printk(KERN_ERR "scsi%d: (%d:%d) no saved request for tag %d\n", host->host_no, reselection_id, lun, hostdata->msgin[2]); BUG(); } @@ -1180,7 +1180,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, slot->cmnd->cmd_len); - + } } else if(dsps == A_RESELECTED_DURING_SELECTION) { @@ -1193,10 +1193,10 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, __u8 reselection_id = NCR_700_readb(host, SFBR_REG); struct NCR_700_command_slot *slot; - + /* Take out our own ID */ reselection_id &= ~(1<this_id); - + /* I've never seen this happen, so keep this as a printk rather * than a debug */ printk(KERN_INFO "scsi%d: (%d:%d) RESELECTION DURING SELECTION, dsp=%08x[%04x] state=%d, count=%d\n", @@ -1222,7 +1222,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, slot->state = NCR_700_SLOT_QUEUED; } hostdata->cmd = NULL; - + if(reselection_id == 0) { if(hostdata->reselection_id == 0xff) { printk(KERN_ERR "scsi%d: Invalid reselection during selection!!\n", host->host_no); @@ -1233,7 +1233,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, reselection_id = hostdata->reselection_id; } } else { - + /* convert to real ID */ reselection_id = bitmap_to_number(reselection_id); } @@ -1251,7 +1251,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, * a return here will re-run the queued command slot * that may have been interrupted by the initial selection */ DEBUG((" SELECTION COMPLETED\n")); - } else if((dsps & 0xfffff0f0) == A_MSG_IN) { + } else if((dsps & 0xfffff0f0) == A_MSG_IN) { resume_offset = process_message(host, hostdata, SCp, dsp, dsps); } else if((dsps & 0xfffff000) == 0) { @@ -1304,7 +1304,7 @@ process_selection(struct Scsi_Host *host, __u32 dsp) /* Take out our own ID */ id &= ~(1<this_id); - if(id != 0) + if(id != 0) break; udelay(5); } @@ -1322,7 +1322,7 @@ process_selection(struct Scsi_Host *host, __u32 dsp) struct NCR_700_command_slot *slot = (struct NCR_700_command_slot *)SCp->host_scribble; DEBUG((" ID %d WARNING: RESELECTION OF BUSY HOST, saving cmd %p, slot %p, addr %x [%04x], resume %x!\n", id, hostdata->cmd, slot, dsp, dsp - hostdata->pScript, resume_offset)); - + switch(dsp - hostdata->pScript) { case Ent_Disconnect1: case Ent_Disconnect2: @@ -1344,7 +1344,7 @@ process_selection(struct Scsi_Host *host, __u32 dsp) case Ent_Finish2: process_script_interrupt(A_GOOD_STATUS_AFTER_STATUS, dsp, SCp, host, hostdata); break; - + default: slot->state = NCR_700_SLOT_QUEUED; break; @@ -1547,7 +1547,7 @@ NCR_700_intr(int irq, void *dev_id) /* clear all the negotiated parameters */ __shost_for_each_device(SDp, host) NCR_700_clear_flag(SDp, ~0); - + /* clear all the slots and their pending commands */ for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) { struct scsi_cmnd *SCp; @@ -1556,7 +1556,7 @@ NCR_700_intr(int irq, void *dev_id) if(slot->state == NCR_700_SLOT_FREE) continue; - + SCp = slot->cmnd; printk(KERN_ERR " failing command because of reset, slot %p, cmnd %p\n", slot, SCp); @@ -1620,7 +1620,7 @@ NCR_700_intr(int irq, void *dev_id) data_transfer += residual; if(data_transfer != 0) { - int count; + int count; __u32 pAddr; SGcount--; @@ -1680,7 +1680,7 @@ NCR_700_intr(int irq, void *dev_id) NCR_700_scsi_done(hostdata, SCp, DID_ERROR<<16); } - + /* NOTE: selection interrupt processing MUST occur * after script interrupt processing to correctly cope * with the case where we process a disconnect and @@ -1718,7 +1718,7 @@ NCR_700_intr(int irq, void *dev_id) DEBUG(("Attempting to resume at %x\n", resume_offset)); NCR_700_clear_fifo(host); NCR_700_writel(resume_offset, host, DSP_REG); - } + } /* There is probably a technical no-no about this: If we're a * shared interrupt and we got this interrupt because the * other device needs servicing not us, we're still going to @@ -1732,7 +1732,7 @@ NCR_700_intr(int irq, void *dev_id) * position we left off */ int j = (i + hostdata->saved_slot_position) % NCR_700_COMMAND_SLOTS_PER_HOST; - + if(hostdata->slots[j].state != NCR_700_SLOT_QUEUED) continue; if(NCR_700_start_command(hostdata->slots[j].cmnd)) { @@ -1752,7 +1752,7 @@ NCR_700_intr(int irq, void *dev_id) static int NCR_700_queuecommand_lck(struct scsi_cmnd *SCp) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0]; __u32 move_ins; struct NCR_700_command_slot *slot; @@ -1852,7 +1852,7 @@ static int NCR_700_queuecommand_lck(struct scsi_cmnd *SCp) default: printk(KERN_ERR "53c700: Unknown command for data direction "); scsi_print_command(SCp); - + move_ins = 0; break; case DMA_NONE: @@ -1937,7 +1937,7 @@ STATIC int NCR_700_host_reset(struct scsi_cmnd * SCp) { DECLARE_COMPLETION_ONSTACK(complete); - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0]; scmd_printk(KERN_INFO, SCp, @@ -1975,9 +1975,9 @@ STATIC void NCR_700_set_period(struct scsi_target *STp, int period) { struct Scsi_Host *SHp = dev_to_shost(STp->dev.parent); - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SHp->hostdata[0]; - + if(!hostdata->fast) return; @@ -1994,11 +1994,11 @@ STATIC void NCR_700_set_offset(struct scsi_target *STp, int offset) { struct Scsi_Host *SHp = dev_to_shost(STp->dev.parent); - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SHp->hostdata[0]; int max_offset = hostdata->chip710 ? NCR_710_MAX_OFFSET : NCR_700_MAX_OFFSET; - + if(!hostdata->fast) return; @@ -2031,7 +2031,7 @@ NCR_700_slave_alloc(struct scsi_device *SDp) STATIC int NCR_700_slave_configure(struct scsi_device *SDp) { - struct NCR_700_Host_Parameters *hostdata = + struct NCR_700_Host_Parameters *hostdata = (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0]; /* to do here: allocate memory; build a queue_full list */ From patchwork Thu Feb 8 08:44:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549439 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93B786D1AA; Thu, 8 Feb 2024 08:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381927; cv=none; b=gOj0INfpeSWwWToc24QmiiDLry8NlBiAQEY9hMeaBwKD3OKIJBil3JSbgy/7dYKYO8p/dEziCugKyqpMUkwcuK2tGUU9FZapljN+uUpUa5voYuvApDVyWFdClDtP4W3/GrnGQSy1myvwmfeKRfYLb+/Zscj92ewnAQbe5nlIai4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381927; c=relaxed/simple; bh=kPQEC7JNk1nG41qzG8wfP+IddSOveAbpNnPvKYhI/4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DmON6N66CxrLyQPExgsS1GkXVS0XCKK33xy4iG8FEYdtMLpnT+vEytHQK9GHTkPBvhvGcHriXJL+qaOI10BvgQQFnoBnL0VsJTMeAUSxzTzLUcvCNgM6Pna2RgERmqAvpCItbmFMDWy+4q6lECHYZs8u565QrL0GpOWYnN8zK6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j4F5tGSr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j4F5tGSr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B7CAC43142; Thu, 8 Feb 2024 08:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381927; bh=kPQEC7JNk1nG41qzG8wfP+IddSOveAbpNnPvKYhI/4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j4F5tGSrD6ALzwj7JwdKg6N+UE+nGeZW0wCkS9VI3EkJV0qqDGxmuGDBKLgCPQXMK iXxeiPa/3/f5uaaaYz5302sabTiuOhOzBQ3WAaWPU5L3nrmQ7mLMjgeE5b6/rSNHZg iOBrDaxlgdQvVyy39RRyZJxP7KnzZULipwN0HI4I836QMXbIwPxkcnvyE3dMNuAKcv /N26Y1C+rCx8iia2dw6Yw1F7QLX21WKuKtqvIEz7S8E7EIR6k7+GxMV4cUwMjHV3Hw MG2SyFuKMKPvNh/hYb4GI3gdbqqybdhXR1QuIXORcwlsinZAWiR9G7QXQ+uigjISdb 7dioSC5x11JAg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Finn Thain , Michael Schmitz , "James E.J. Bottomley" , "Martin K. Petersen" , drew@colorado.edu, Tnx to , linux-scsi@vger.kernel.org Subject: [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:15 +0000 Message-ID: <20240208084512.3803250-4-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a general misunderstanding amongst engineers that {v}snprintf() returns the length of the data *actually* encoded into the destination array. However, as per the C99 standard {v}snprintf() really returns the length of the data that *would have been* written if there were enough space for it. This misunderstanding has led to buffer-overruns in the past. It's generally considered safer to use the {v}scnprintf() variants in their place (or even sprintf() in simple cases). So let's do that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Finn Thain Cc: Michael Schmitz Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: drew@colorado.edu Cc: Tnx to Cc: linux-scsi@vger.kernel.org --- drivers/scsi/NCR5380.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c index cea3a79d538e4..ea565e843c765 100644 --- a/drivers/scsi/NCR5380.c +++ b/drivers/scsi/NCR5380.c @@ -421,14 +421,14 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags) if (!hostdata->work_q) return -ENOMEM; - snprintf(hostdata->info, sizeof(hostdata->info), - "%s, irq %d, io_port 0x%lx, base 0x%lx, can_queue %d, cmd_per_lun %d, sg_tablesize %d, this_id %d, flags { %s%s%s}", - instance->hostt->name, instance->irq, hostdata->io_port, - hostdata->base, instance->can_queue, instance->cmd_per_lun, - instance->sg_tablesize, instance->this_id, - hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", - hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", - hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); + scnprintf(hostdata->info, sizeof(hostdata->info), + "%s, irq %d, io_port 0x%lx, base 0x%lx, can_queue %d, cmd_per_lun %d, sg_tablesize %d, this_id %d, flags { %s%s%s}", + instance->hostt->name, instance->irq, hostdata->io_port, + hostdata->base, instance->can_queue, instance->cmd_per_lun, + instance->sg_tablesize, instance->this_id, + hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", + hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", + hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); NCR5380_write(MODE_REG, MR_BASE); From patchwork Thu Feb 8 08:44:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549440 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 061A76F50E; Thu, 8 Feb 2024 08:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381929; cv=none; b=PuxU7Pxv8ALkJrMwC54G/g7fmS8kZSFVl/gmehvS2cPweZNg4BHkWC7nRgtuw7/xCWA9pXR9nCeiCVn29ZnycXpWdcwF9uR1B1NLLrOVEWz1Ave+kGxlO+DIkIizH9SQYYmk/Sh1yQ+rYBYSYH7INXwBFGaUuXZEnj6Beg9xMcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381929; c=relaxed/simple; bh=Z2CP+O5Bv9LbkXXAh5F8xDT7ZCfBYn4Mn2nqmn37ldw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qYDKVCT2vptlHlrH7QLbHOwo6FAmqL9d9/BxBKk+35znhSBiNNRl2NIEFDOC2sZDM0LKk72Oeqf47l/bSBBGqqD458/YszqNlXm8lH4jFFv9zMoyRv/G9c3RvwiD2ecf+L8QIx26pd3BwpaMFzyWn6JeTleHjh27OS0H93R4UZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MNxilidQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MNxilidQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 721C2C43394; Thu, 8 Feb 2024 08:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381928; bh=Z2CP+O5Bv9LbkXXAh5F8xDT7ZCfBYn4Mn2nqmn37ldw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNxilidQzOvdSPg22Q6azfmgMcS4E2C/rBzHDGxIpkSY0f83QhtuhCxMwfxhldgwD LLbe9tmty92PjuqBCqdNdX07LGA02ZVepLkQPlqK4Pfzcr65X1l/8FBnE2oNX+TwhX /N85C1wBdDetTek4BewQukeCTSDFf17sBn9sZBWRiYR5Z+gRMj5Hj3MrA1TOD42KQ7 UUPKr5jWJqoEIbhv7mP45UDHfVqoJYLDp0sXWqYoYuIpBghDBjSgDSC4V3w9skguj7 RzgIZMAGtlAcIXi69/qOqKosBgbeQwHSbLBRT2IpItV/g9NnoEItd1iny1Cfk6lgmP jmNIqcBhhhSdg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Adaptec OEM Raid Solutions , "James E.J. Bottomley" , "Martin K. Petersen" , "PMC-Sierra, Inc" , linux-scsi@vger.kernel.org Subject: [PATCH 04/10] scsi: aacraid: linit: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 8 Feb 2024 08:44:16 +0000 Message-ID: <20240208084512.3803250-5-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Adaptec OEM Raid Solutions Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: "PMC-Sierra, Inc" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aacraid/linit.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c index 68f4dbcfff492..69526e2bd2e78 100644 --- a/drivers/scsi/aacraid/linit.c +++ b/drivers/scsi/aacraid/linit.c @@ -558,11 +558,9 @@ static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute * struct scsi_device *sdev = to_scsi_device(dev); struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata); if (sdev_channel(sdev) != CONTAINER_CHANNEL) - return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach - ? "Hidden\n" : + return sysfs_emit(buf, sdev->no_uld_attach ? "Hidden\n" : ((aac->jbod && (sdev->type == TYPE_DISK)) ? "JBOD\n" : "")); - return snprintf(buf, PAGE_SIZE, "%s\n", - get_container_type(aac->fsa_dev[sdev_id(sdev)].type)); + return sysfs_emit(buf, "%s\n", get_container_type(aac->fsa_dev[sdev_id(sdev)].type)); } static struct device_attribute aac_raid_level_attr = { @@ -1195,10 +1193,9 @@ static ssize_t aac_show_model(struct device *device, ++cp; while (*cp == ' ') ++cp; - len = snprintf(buf, PAGE_SIZE, "%s\n", cp); + len = sysfs_emit(buf, "%s\n", cp); } else - len = snprintf(buf, PAGE_SIZE, "%s\n", - aac_drivers[dev->cardtype].model); + len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].model); return len; } @@ -1214,12 +1211,11 @@ static ssize_t aac_show_vendor(struct device *device, char *cp = sup_adap_info->adapter_type_text; while (*cp && *cp != ' ') ++cp; - len = snprintf(buf, PAGE_SIZE, "%.*s\n", + len = sysfs_emit(buf, "%.*s\n", (int)(cp - (char *)sup_adap_info->adapter_type_text), sup_adap_info->adapter_type_text); } else - len = snprintf(buf, PAGE_SIZE, "%s\n", - aac_drivers[dev->cardtype].vname); + len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].vname); return len; } @@ -1230,7 +1226,7 @@ static ssize_t aac_show_flags(struct device *cdev, struct aac_dev *dev = (struct aac_dev*)class_to_shost(cdev)->hostdata; if (nblank(dprintk(x))) - len = snprintf(buf, PAGE_SIZE, "dprintk\n"); + len = sysfs_emit(buf, "dprintk\n"); #ifdef AAC_DETAILED_STATUS_INFO len += scnprintf(buf + len, PAGE_SIZE - len, "AAC_DETAILED_STATUS_INFO\n"); @@ -1258,7 +1254,7 @@ static ssize_t aac_show_kernel_version(struct device *device, int len, tmp; tmp = le32_to_cpu(dev->adapter_info.kernelrev); - len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n", + len = sysfs_emit(buf, "%d.%d-%d[%d]\n", tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff, le32_to_cpu(dev->adapter_info.kernelbuild)); return len; @@ -1272,7 +1268,7 @@ static ssize_t aac_show_monitor_version(struct device *device, int len, tmp; tmp = le32_to_cpu(dev->adapter_info.monitorrev); - len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n", + len = sysfs_emit(buf, "%d.%d-%d[%d]\n", tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff, le32_to_cpu(dev->adapter_info.monitorbuild)); return len; @@ -1286,7 +1282,7 @@ static ssize_t aac_show_bios_version(struct device *device, int len, tmp; tmp = le32_to_cpu(dev->adapter_info.biosrev); - len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n", + len = sysfs_emit(buf, "%d.%d-%d[%d]\n", tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff, le32_to_cpu(dev->adapter_info.biosbuild)); return len; @@ -1296,7 +1292,7 @@ static ssize_t aac_show_driver_version(struct device *device, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version); + return sysfs_emit(buf, "%s\n", aac_driver_version); } static ssize_t aac_show_serial_number(struct device *device, @@ -1322,15 +1318,13 @@ static ssize_t aac_show_serial_number(struct device *device, static ssize_t aac_show_max_channel(struct device *device, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", - class_to_shost(device)->max_channel); + return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_channel); } static ssize_t aac_show_max_id(struct device *device, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", - class_to_shost(device)->max_id); + return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_id); } static ssize_t aac_store_reset_adapter(struct device *device, @@ -1360,7 +1354,7 @@ static ssize_t aac_show_reset_adapter(struct device *device, tmp = aac_adapter_check_health(dev); if ((tmp == 0) && dev->in_reset) tmp = -EBUSY; - len = snprintf(buf, PAGE_SIZE, "0x%x\n", tmp); + len = sysfs_emit(buf, "0x%x\n", tmp); return len; } From patchwork Thu Feb 8 08:44:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549441 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD9E76F50B; Thu, 8 Feb 2024 08:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381930; cv=none; b=pRNvSYdpR6WtHe0ixlMojdHwOLJw2ek08pdHY5Gh/THdpAHUK0RktIrMgFf4ETHlQvyCHYMf0eYDQwP6ccsLhYhAPHOVHcO47NPJcyVbhzRRdxCO/7xqPIvqELZ0TfzyOcYK1d/Z+m7/6g0mXEg1AsCfNK9zopYMVjv7taI6kRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381930; c=relaxed/simple; bh=POI6uCurjz7K0SS0gUH7C3Dj3W11IBfcHS/B+rMzmkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzKDprN1HdM+KjIMnES3wfAaXrhCWSlkBmRcPwwVZw9/u8IcUpH6K1vPXoVcp7QdC+67ffTUJJJoqHccse8M3njbSqeJCH8e+DF5U2RsRHSwnl5KNwOH7OQycsLSUV43WqbMp/tD/LGNY5ReMtcRSS2D43o0Hjd4mg/NbVmXItY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oj59yN2b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oj59yN2b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35D6BC43390; Thu, 8 Feb 2024 08:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381930; bh=POI6uCurjz7K0SS0gUH7C3Dj3W11IBfcHS/B+rMzmkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oj59yN2bU3sJBgizsn6x4fu41c/QIs6ntSTGN6Z6dvCS6XlPGrpVhwSHlXNhm9jYA BBwC+V2MHkoX+xdCMOcKeEIgSyivDMoGE33cZyG8h5dsmw80W5L7ddNrgWnq+JOGOY hVto3EU37cOv/sJvJH7tQRWIIqxk9tMHVc0myon3u/a8NBRPOaPeZVHf3dGTA/3YYl RzeI1rmPJ/BZHLFQx9+ctK99WAV7ebDzgMq9h7lQULRsUzX6IvJzq3SpsaZ8uOUMzL TkZe+CbIPCDJmesRHbtfmWSdsLeR2vbt0ClkeMbRGCnu0VDW4/w3fLJIgkg53EXybs pXeitHIQV0JkQ== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Adaptec OEM Raid Solutions , "James E.J. Bottomley" , "Martin K. Petersen" , "PMC-Sierra, Inc" , linux-scsi@vger.kernel.org Subject: [PATCH 05/10] scsi: aacraid: linit: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:17 +0000 Message-ID: <20240208084512.3803250-6-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a general misunderstanding amongst engineers that {v}snprintf() returns the length of the data *actually* encoded into the destination array. However, as per the C99 standard {v}snprintf() really returns the length of the data that *would have been* written if there were enough space for it. This misunderstanding has led to buffer-overruns in the past. It's generally considered safer to use the {v}scnprintf() variants in their place (or even sprintf() in simple cases). So let's do that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones --- Cc: Adaptec OEM Raid Solutions Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: "PMC-Sierra, Inc" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aacraid/linit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c index 69526e2bd2e78..0e47d9c4cff23 100644 --- a/drivers/scsi/aacraid/linit.c +++ b/drivers/scsi/aacraid/linit.c @@ -583,7 +583,7 @@ static ssize_t aac_show_unique_id(struct device *dev, if (sdev_channel(sdev) == CONTAINER_CHANNEL) memcpy(sn, aac->fsa_dev[sdev_id(sdev)].identifier, sizeof(sn)); - return snprintf(buf, 16 * 2 + 2, + return scnprintf(buf, 16 * 2 + 2, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", sn[0], sn[1], sn[2], sn[3], sn[4], sn[5], sn[6], sn[7], @@ -1302,13 +1302,13 @@ static ssize_t aac_show_serial_number(struct device *device, int len = 0; if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0) - len = snprintf(buf, 16, "%06X\n", + len = scnprintf(buf, 16, "%06X\n", le32_to_cpu(dev->adapter_info.serial[0])); if (len && !memcmp(&dev->supplement_adapter_info.mfg_pcba_serial_no[ sizeof(dev->supplement_adapter_info.mfg_pcba_serial_no)-len], buf, len-1)) - len = snprintf(buf, 16, "%.*s\n", + len = scnprintf(buf, 16, "%.*s\n", (int)sizeof(dev->supplement_adapter_info.mfg_pcba_serial_no), dev->supplement_adapter_info.mfg_pcba_serial_no); From patchwork Thu Feb 8 08:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549442 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DC7371B4D; Thu, 8 Feb 2024 08:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381933; cv=none; b=mBW3B3d6pI8fMVCqMGsEJ1yCBoWlnRRpAhNhmUckW6SKupjNUijJkYQxxs39wFTbEFdyitu/mLXzWpCxKKlsk7uwoXybugGl/0xrnX8Rb2jRCG2hcjfldQEREL4NdFwbK4iihNJ4WiFjD9c+gpicmKEgotfOD9xJ2VLKEtRJx5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381933; c=relaxed/simple; bh=PbzPd7ROc5va5PvBniGi9yT6iZxcViGR7FsGtUiYZPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ax340BOOpImeQx4RMtE5KZ8gORbhvmtEyCceuXWAQwz3GV7QtcS30zAWS+bcRwBA5XxycrFrx15NGfQn+J5vBYHk+TDHnePeltwPi1rdUfYYr1ZqmmbiKz9P3eYhzaqEmtjPrdyiUiG2gb9k7RacFeGdEGDdUh2zy8MvBFhXLJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JYv3wWWf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JYv3wWWf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECCBEC43394; Thu, 8 Feb 2024 08:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381932; bh=PbzPd7ROc5va5PvBniGi9yT6iZxcViGR7FsGtUiYZPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYv3wWWfitgg/S4wiWCNHUkrl6YEq7UHvBTMANfUjrWE6exn3/m3eE4TUhkWPXN+Y rRCC2FVaAkQZqV1mHCuFnaHh1E4JzU8l38xR/iT/qXy3v/vrN2OxQVG3lrZhMJjvCx o4T+oxyev2+cxar+vWyjTi6fPg7ODFt8JIJFQLVx0HGBORpVmo99miUmNAWAEXz00J mMdCOBIQwXoI84M6/sfhzlFbrNwoOdvX9cGpijg9bbVq5vEsPeuulOXxkJeOp03YD5 OMN6+cLmOLws/InUorErs1VlC3zfGGKrspeOEalGaY6iN4L2ycp8QkTyggjGOJ6JbQ S9VvuxHfX7/Ug== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 06/10] scsi: aha1542: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:18 +0000 Message-ID: <20240208084512.3803250-7-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a general misunderstanding amongst engineers that {v}snprintf() returns the length of the data *actually* encoded into the destination array. However, as per the C99 standard {v}snprintf() really returns the length of the data that *would have been* written if there were enough space for it. This misunderstanding has led to buffer-overruns in the past. It's generally considered safer to use the {v}scnprintf() variants in their place (or even sprintf() in simple cases). So let's do that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aha1542.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c index 9503996c63256..b5ec7887801a5 100644 --- a/drivers/scsi/aha1542.c +++ b/drivers/scsi/aha1542.c @@ -772,7 +772,7 @@ static struct Scsi_Host *aha1542_hw_init(const struct scsi_host_template *tpnt, goto unregister; if (sh->dma_channel != 0xFF) - snprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel); + scnprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel); shost_printk(KERN_INFO, sh, "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d, %s\n", sh->this_id, base_io, sh->irq, dma_info); if (aha1542->bios_translation == BIOS_TRANSLATION_25563) From patchwork Thu Feb 8 08:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549443 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 355D271B58; Thu, 8 Feb 2024 08:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381934; cv=none; b=iBQOgW5CcxPy1nLu58I3GFl8OCwbtmc/Lk7VrKJqOGM4TO615LPMpiz7nOjxtAkJ2n0oH48XiBbIK79A1efMpd5q/6wK7teAiFWs9pph174Sz6K1cG2lpe3a7j7NRI1H4o0AVvuy+IsF9k0LKt/K+8clJMf+cwZIgzT4LuofA2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381934; c=relaxed/simple; bh=WGjy4Cm0cEOn+F+u0AjX0H2bpY30XTKx3DCJD60T9WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KsCRccDtfe1zXF6GNw22OxvLl5aJsaA+Yi7Io+lsoXYDV2PNSH8bV34MQiH9EyJN7183KkeVgBR0hsbioF9iZLKwbASYL1eSrOugjat2XjT4sXVKo7R4/lWvzelhp+U/v0/xGoxgHu2GZZgDncsjiYSH7YUck6asCgAeMnbkqR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nY08ObA9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nY08ObA9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69997C433F1; Thu, 8 Feb 2024 08:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381933; bh=WGjy4Cm0cEOn+F+u0AjX0H2bpY30XTKx3DCJD60T9WI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nY08ObA9mT1r7BdDI4+PYZMJ5u34xPUmGzv18dfsF8Em8732jTJOMbNbTyoN87pF9 fc8fw9r6k5sKza1jJjXSIT5b/1FhiNa9UvFTNwCYHUVBjFyPU3R7BrVKPfOvtyyVZO to0fM5gFUcrWWbx7m5NaeEa0mxxzeRg/xWziXcGG7XbyIwkt4M4nT78CcLTMOca3e3 z6vd+9tRfdOHtqKky+XLcZDol0BzBUbyqoMoVtt52FCv/dRhqR/3z6OtBi1laxffHx BshFNRs59+jDW671Jzz16Zxz50WXaAoYuCER6s2pj42+1x8utsSZXLmnGiVE9EoBYw 5c41mD3T6eUaQ== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 07/10] scsi: aic7xxx: aicasm: Trivial: Remove trailing whitespace Date: Thu, 8 Feb 2024 08:44:19 +0000 Message-ID: <20240208084512.3803250-8-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Removing out of need rather than want. I wish to make proper changes to this file, but my editor is insistent on removing whitespace on save. Rather than go down the rabbit hole of debugging my editor right now, I'd rather stay productive. So, out it comes! EDIT: Found it. Looks like 5a602de99797b ("Add .editorconfig file for basic formatting") now forces editors to trim whitespace. Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Hannes Reinecke Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aic7xxx/aicasm/aicasm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c index cd692a4c5f857..8d995186e557a 100644 --- a/drivers/scsi/aic7xxx/aicasm/aicasm.c +++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c @@ -132,7 +132,7 @@ main(int argc, char *argv[]) /* Set Sentinal scope node */ sentinal = scope_alloc(); sentinal->type = SCOPE_ROOT; - + includes_search_curdir = 1; appname = *argv; regfile = NULL; @@ -553,7 +553,7 @@ output_listing(char *ifilename) if (func_values == NULL) stop("Could not malloc", EX_OSERR); - + func_values[0] = 0; /* FALSE func */ func_count--; @@ -561,13 +561,13 @@ output_listing(char *ifilename) * Ask the user to fill in the return values for * the rest of the functions. */ - - + + for (cur_func = SLIST_FIRST(&patch_functions); cur_func != NULL && SLIST_NEXT(cur_func, links) != NULL; cur_func = SLIST_NEXT(cur_func, links), func_count--) { int input; - + fprintf(stdout, "\n(%s)\n", cur_func->symbol->name); fprintf(stdout, "Enter the return value for " @@ -751,7 +751,7 @@ cs_alloc() if (new_cs == NULL) stop("Unable to malloc critical_section object", EX_SOFTWARE); memset(new_cs, 0, sizeof(*new_cs)); - + TAILQ_INSERT_TAIL(&cs_tailq, new_cs, links); return new_cs; } @@ -766,7 +766,7 @@ scope_alloc() stop("Unable to malloc scope object", EX_SOFTWARE); memset(new_scope, 0, sizeof(*new_scope)); TAILQ_INIT(&new_scope->inner_scope); - + if (SLIST_FIRST(&scope_stack) != NULL) { TAILQ_INSERT_TAIL(&SLIST_FIRST(&scope_stack)->inner_scope, new_scope, scope_links); From patchwork Thu Feb 8 08:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549444 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEF3973197; Thu, 8 Feb 2024 08:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381935; cv=none; b=P5SIe56mslZgqf4RR5nwrJDU9Yk1J9q87rR60UE8q21T7MMvb5y4xU+TCseACIZnx+QIc8OcQYwFfoX+TNeDCljTXMMX4PZ4i26Ca1lP0E/+kisWZRrORX02sqxThLQsfUURFOl3zvRDO+cfvuPhSG1zKF7N1BGVRnG7VUHQZsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381935; c=relaxed/simple; bh=QcWkvLbuXqKsmCSILThA1RfLwMeDripObvnvLFWiq34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fDe2rypoyWtpnB06izoJQSLDq47rc6o3uHT2waOB85hlw/BcTJUUZnfYbeUp3EsQTDq0EUcNO5rxyjbhb5E1slsTIchW3Sazk6TiYqp9A765vXVJLh0DLs7RkcMVnVY7uDeFdKCMumFBfiXUhV5RtL7qjQX2wiJkpj5Ilpu9JNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flkB5vKC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="flkB5vKC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A257C433C7; Thu, 8 Feb 2024 08:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381935; bh=QcWkvLbuXqKsmCSILThA1RfLwMeDripObvnvLFWiq34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=flkB5vKCBQYz/TpY0INSUaOZjllm7VrkDUbKFVgCIc3ASXj/qazrW94Yryh3JnsNX NJlgNNRcRUnXProGsUi8C60pgUya/Fr+EbvRfWtqbhO2YHZE25gcmPGLdWv0WujarZ cWbsO1A+1oAk30b0gsn/JJRxxxx7v+Ya+QMQQeTauB49jBXRvaud7rZaPGDH6v1Sm9 BshS6lbql3Lky3xkzhJ3qkII+o16i592ZP1lJ90hMoELZdsv6nOxN6LrniXK5qTPYr QEA8Dul1ponHXK0/KmqqAqeurIbVE98UbjMLuIfEWXQG0CQZgxl22y8j+OgKOr8sY/ u8EUQhEi+CBGg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 08/10] scsi: aic7xxx: aicasm: Replace snprintf() with the safer scnprintf() variant Date: Thu, 8 Feb 2024 08:44:20 +0000 Message-ID: <20240208084512.3803250-9-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a general misunderstanding amongst engineers that {v}snprintf() returns the length of the data *actually* encoded into the destination array. However, as per the C99 standard {v}snprintf() really returns the length of the data that *would have been* written if there were enough space for it. This misunderstanding has led to buffer-overruns in the past. It's generally considered safer to use the {v}scnprintf() variants in their place (or even sprintf() in simple cases). So let's do that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: Hannes Reinecke Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: Lee Jones Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aic7xxx/aicasm/aicasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c index 8d995186e557a..bc758e78d3c06 100644 --- a/drivers/scsi/aic7xxx/aicasm/aicasm.c +++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c @@ -331,7 +331,7 @@ back_patch() if (cur_instr->patch_label->type != LABEL) { char buf[255]; - snprintf(buf, sizeof(buf), + scnprintf(buf, sizeof(buf), "Undefined label %s", cur_instr->patch_label->name); stop(buf, EX_DATAERR); From patchwork Thu Feb 8 08:44:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549445 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702AC76026; Thu, 8 Feb 2024 08:45:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381937; cv=none; b=hhjbRqxB40t4BvmfYSTN/D582LT6/uvh1HD7WeffP0D25EX09pQCL2JEtu1YJisjeBw0fqVKrmi0sdTUIvnFm0HlEkF796H/UA1n012sFuXhI5lqenfaZuBXuN39AhzFOVBBCiMb+tdjAP4Y5YL88fnK+peuEt8eDBoQ7135rTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381937; c=relaxed/simple; bh=lMT5ds09tPKnvt5Z0XoIWL0MTp/63mQAtpaTLMS6Bp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvMA2J2qSZEdw0hZErbGteyrLrWJhalxQRYfJk6vLMB/tkvzTBTgddfdaBOeoH/wcJOfc+imY0JRhPeg8auWB2BclF9yYdK7Mp5N3R/fziVbzt2Mn1w16QwIv59GE2rcdFpaPLBvA037rIPF0vM0VZxqjZnIXc8IxjVibrYNB9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J+AyC1IJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J+AyC1IJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CEFEC43399; Thu, 8 Feb 2024 08:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381937; bh=lMT5ds09tPKnvt5Z0XoIWL0MTp/63mQAtpaTLMS6Bp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+AyC1IJGKuoOUKM5zUpx63JFqLmK3QCBMLMNCt2a87u7tEU2INr5mCviZhYP0aY4 jE+FZIXhMhOtL29JNAm/HuvP83u7gFMWthjuqXFRePQ2ccCLhWzb0P61wzQQGncLvY Wq+d7cvzmlMBf3QGUprdbxancpf64qlSJ+G+LbUosm8B8m6hhaqb0ZG2qC7L2uwgBa jRFgq2L8l84PNrXWXGck3eqqxs1MuTR8RRwAPmgdmAUOJIZzh8bixKKsR47yefhpKQ FS+pCBiRWxQMQxdOlSMZvgoXMhzs/81weorCR11zGzY79j2ctTvt+MoDfrj5gcDC09 +oCg4Lw/QFfYA== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , John Garry , Luben Tuikov , linux-scsi@vger.kernel.org Subject: [PATCH 09/10] scsi: aic94xx: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 8 Feb 2024 08:44:21 +0000 Message-ID: <20240208084512.3803250-10-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: John Garry Cc: Luben Tuikov Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aic94xx/aic94xx_init.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index 8a3340d8d7ad4..c976e4b77c71e 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -264,8 +264,7 @@ static ssize_t asd_show_dev_rev(struct device *dev, struct device_attribute *attr, char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%s\n", - asd_dev_rev[asd_ha->revision_id]); + return sysfs_emit(buf, "%s\n", asd_dev_rev[asd_ha->revision_id]); } static DEVICE_ATTR(aic_revision, S_IRUGO, asd_show_dev_rev, NULL); @@ -273,7 +272,7 @@ static ssize_t asd_show_dev_bios_build(struct device *dev, struct device_attribute *attr,char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%d\n", asd_ha->hw_prof.bios.bld); + return sysfs_emit(buf, "%d\n", asd_ha->hw_prof.bios.bld); } static DEVICE_ATTR(bios_build, S_IRUGO, asd_show_dev_bios_build, NULL); @@ -281,7 +280,7 @@ static ssize_t asd_show_dev_pcba_sn(struct device *dev, struct device_attribute *attr, char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%s\n", asd_ha->hw_prof.pcba_sn); + return sysfs_emit(buf, "%s\n", asd_ha->hw_prof.pcba_sn); } static DEVICE_ATTR(pcba_sn, S_IRUGO, asd_show_dev_pcba_sn, NULL); @@ -452,7 +451,7 @@ static ssize_t asd_show_update_bios(struct device *dev, if (asd_ha->bios_status != FLASH_IN_PROGRESS) asd_ha->bios_status = FLASH_OK; - return snprintf(buf, PAGE_SIZE, "status=%x %s\n", + return sysfs_emit(buf, "status=%x %s\n", flash_error_table[i].err_code, flash_error_table[i].reason); } @@ -937,7 +936,7 @@ static int asd_scan_finished(struct Scsi_Host *shost, unsigned long time) static ssize_t version_show(struct device_driver *driver, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", ASD_DRIVER_VERSION); + return sysfs_emit(buf, "%s\n", ASD_DRIVER_VERSION); } static DRIVER_ATTR_RO(version); From patchwork Thu Feb 8 08:44:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13549446 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C056E74E2A; Thu, 8 Feb 2024 08:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381938; cv=none; b=XvpprrpUgadia5CVM1NSfbgfarfEg2WH3gAFQsQQQ/RMtNqLK9CMP09m9oZfyaSzCDTQUCw8UC82r1TDvo6ejO9arz3C8Uah3zWxuBqIEkbYXwvjwKav66MOquzOCS5knTWGAjwg0A3uhAGOkQe7A2LOs2rOJq/r2Vc/UI7eNyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381938; c=relaxed/simple; bh=qmbHfN/f8YgSLjrFL2hPNhuDBX1LYqccIkoXslfVQ1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rRrK3aks/8IQLgXXaD9OhBbxitdQf8znf7J0WXTZz27P6djHe7VX4KzeiHhR87JYXwX1iZZSF+Is6sNxEnKZXHVoI+GYwbuTYKZzGCT5Dhu4aNM3vUk2t7bYT/pDC7+ZNkQql88yrraDSq3eNIvbqzcB3qvuj7z64a8IhLnjIv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LOEmzCzg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LOEmzCzg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E6F1C433B1; Thu, 8 Feb 2024 08:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381938; bh=qmbHfN/f8YgSLjrFL2hPNhuDBX1LYqccIkoXslfVQ1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LOEmzCzgxxjlFn+1XmC8QqhwKpmjJFNJilrBiaaa5pcylqyqEEg8E4wf2GwOCaUU9 fegkkGzEwK1cmtc+QpLPwbHg96F2C7Ie9tVls5Ah66PKkdfldLMY9XXQaNy+MNK3dQ TzGwHdq/qNrgG/Cr+pjuxFRRm9NPhHiumqhc+QF3WTcRiCnwaCytOg2fObaVSrBmY3 ox5G+HNe7WQOAeVbl057M+XYrRXShmn+DlS41O5L/tlxnFXemnFTuln958Q11MuV1e mbJcvIB59oJizF3UieAN2VSxFeZK+qYR8l+ueWh663SQ/ZO+NG9tBSATUUryXlpqrB XKnFiJpyUgDUQ== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , support@areca.com.tw, linux-scsi@vger.kernel.org Subject: [PATCH 10/10] scsi: arcmsr: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 8 Feb 2024 08:44:22 +0000 Message-ID: <20240208084512.3803250-11-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones Reviewed-by: Kees Cook --- Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: support@areca.com.tw Cc: linux-scsi@vger.kernel.org --- drivers/scsi/arcmsr/arcmsr_attr.c | 40 ++++++++----------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c index baeb5e7956902..c430c835503be 100644 --- a/drivers/scsi/arcmsr/arcmsr_attr.c +++ b/drivers/scsi/arcmsr/arcmsr_attr.c @@ -258,9 +258,7 @@ static ssize_t arcmsr_attr_host_driver_version(struct device *dev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, - "%s\n", - ARCMSR_DRIVER_VERSION); + return sysfs_emit(buf, "%s\n", ARCMSR_DRIVER_VERSION); } static ssize_t @@ -270,9 +268,7 @@ arcmsr_attr_host_driver_posted_cmd(struct device *dev, struct Scsi_Host *host = class_to_shost(dev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - atomic_read(&acb->ccboutstandingcount)); + return sysfs_emit(buf, "%4d\n", atomic_read(&acb->ccboutstandingcount)); } static ssize_t @@ -282,9 +278,7 @@ arcmsr_attr_host_driver_reset(struct device *dev, struct Scsi_Host *host = class_to_shost(dev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->num_resets); + return sysfs_emit(buf, "%4d\n", acb->num_resets); } static ssize_t @@ -294,9 +288,7 @@ arcmsr_attr_host_driver_abort(struct device *dev, struct Scsi_Host *host = class_to_shost(dev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->num_aborts); + return sysfs_emit(buf, "%4d\n", acb->num_aborts); } static ssize_t @@ -306,9 +298,7 @@ arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr, struct Scsi_Host *host = class_to_shost(dev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%s\n", - acb->firm_model); + return sysfs_emit(buf, "%s\n", acb->firm_model); } static ssize_t @@ -319,9 +309,7 @@ arcmsr_attr_host_fw_version(struct device *dev, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%s\n", - acb->firm_version); + return sysfs_emit(buf, "%s\n", acb->firm_version); } static ssize_t @@ -332,9 +320,7 @@ arcmsr_attr_host_fw_request_len(struct device *dev, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->firm_request_len); + return sysfs_emit(buf, "%4d\n", acb->firm_request_len); } static ssize_t @@ -345,9 +331,7 @@ arcmsr_attr_host_fw_numbers_queue(struct device *dev, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->firm_numbers_queue); + return sysfs_emit(buf, "%4d\n", acb->firm_numbers_queue); } static ssize_t @@ -358,9 +342,7 @@ arcmsr_attr_host_fw_sdram_size(struct device *dev, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->firm_sdram_size); + return sysfs_emit(buf, "%4d\n", acb->firm_sdram_size); } static ssize_t @@ -371,9 +353,7 @@ arcmsr_attr_host_fw_hd_channels(struct device *dev, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; - return snprintf(buf, PAGE_SIZE, - "%4d\n", - acb->firm_hd_channels); + return sysfs_emit(buf, "%4d\n", acb->firm_hd_channels); } static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);