Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/hp300/dev Check bounds of each partition by MI boun...



details:   https://anonhg.NetBSD.org/src/rev/297da0e63cd0
branches:  trunk
changeset: 372464:297da0e63cd0
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Wed Nov 30 16:37:44 2022 +0000

description:
Check bounds of each partition by MI bounds_check_with_label(9).

The previous implementation was committed in rev 1.26 about 26 years ago
and it looks there is no quirk to use the old MD one.

diffstat:

 sys/arch/hp300/dev/rd.c |  36 +++++-------------------------------
 1 files changed, 5 insertions(+), 31 deletions(-)

diffs (72 lines):

diff -r b081bc7633ad -r 297da0e63cd0 sys/arch/hp300/dev/rd.c
--- a/sys/arch/hp300/dev/rd.c   Wed Nov 30 15:59:01 2022 +0000
+++ b/sys/arch/hp300/dev/rd.c   Wed Nov 30 16:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rd.c,v 1.115 2022/11/30 15:59:01 tsutsui Exp $ */
+/*     $NetBSD: rd.c,v 1.116 2022/11/30 16:37:44 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.115 2022/11/30 15:59:01 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.116 2022/11/30 16:37:44 tsutsui Exp $");
 
 #include "opt_useleds.h"
 
@@ -877,7 +877,7 @@
        struct rd_softc *sc = device_lookup_private(&rd_cd, rdunit(bp->b_dev));
        struct partition *pinfo;
        daddr_t bn;
-       int sz, s;
+       int s;
        int offset;
 
 #ifdef DEBUG
@@ -887,7 +887,6 @@
                       (bp->b_flags & B_READ) ? 'R' : 'W');
 #endif
        bn = bp->b_blkno;
-       sz = howmany(bp->b_bcount, DEV_BSIZE);
        pinfo = &sc->sc_dkdev.dk_label->d_partitions[rdpart(bp->b_dev)];
 
        /* Don't perform partition translation on RAW_PART. */
@@ -898,34 +897,9 @@
                    rdidentinfo[sc->sc_type].ri_nblocks) <= 0)
                        goto done;
        } else {
-               /*
-                * XXX This block of code belongs in
-                * XXX bounds_check_with_label()
-                */
-
-               if (bn < 0 || bn + sz > pinfo->p_size) {
-                       sz = pinfo->p_size - bn;
-                       if (sz == 0) {
-                               bp->b_resid = bp->b_bcount;
-                               goto done;
-                       }
-                       if (sz < 0) {
-                               bp->b_error = EINVAL;
-                               goto done;
-                       }
-                       bp->b_bcount = dbtob(sz);
-               }
-               /*
-                * Check for write to write protected label
-                */
-               if (bn + offset <= LABELSECTOR &&
-#if LABELSECTOR != 0
-                   bn + offset + sz > LABELSECTOR &&
-#endif
-                   !(bp->b_flags & B_READ) && !(sc->sc_flags & RDF_WLABEL)) {
-                       bp->b_error = EROFS;
+               if (bounds_check_with_label(&sc->sc_dkdev, bp,
+                   (sc->sc_flags & RDF_WLABEL) != 0) <= 0)
                        goto done;
-               }
        }
        bp->b_rawblkno = bn + offset;
        s = splbio();



Home | Main Index | Thread Index | Old Index